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


(local
    local0 = 250
    local1[56] = (18 115 42 97 92 85 119 55 130 51 151 66 159 65 163 58 175 52 193 61 211 60 256 67 275 84 274 95 261 104 249 104 230 120 217 119 215 131 184 137 182 146 162 148 107 142 93 134 80 131 63 110 48 119 18 125 )
    local57[10] = (127 122 153 112 159 123 149 131 129 132 )
    local67[12] = (219 120 218 131 206 136 197 132 197 122 205 116 )

)
(procedure (localproc_0fca param1 param2 param3 param4)
    (var temp0, temp1, temp2)
    (send gLongSong2:
        number(105)
        vol(127)
        loop(1)
        play()
    )
    (if (< param1 param3)
        = temp0 (- param1 1)
        = temp1 (+ param3 1)
    )(else
        = temp0 (- param3 1)
        = temp1 (+ param1 1)
    )
    = temp2 Graph(7 temp0 (- param2 1) temp1 (+ param4 1) 1)
    Graph(4 param1 param2 param3 param4 global143 -1 -1)
    Graph(13 temp0 - param2 1 temp1 + param4 1)
    Wait(1)
    Wait(4)
    Graph(8 temp2)
    Graph(13 temp0 - param2 1 temp1 + param4 1)
)


(instance public rm045 of SQRoom
    (properties
        style 30
        horizon 150
        north 30
        east 50
        south 60
        west 40
    )

    (method (init)
        proc958_0(128 4 27 46)
        proc958_0(132 149)
        Load(rsSCRIPT 956)
        (switch (global12)
            (case 25
                (send gEgo:
                    x(20)
                    y(+ horizon (send gEgo:yStep))
                )
            )
            (case 30
                (send gEgo:
                    loop(2)
                    x(
                        (if (< (send gEgo:x) 80)
                            80
                        )(else
                            (if (> (send gEgo:x) 240)
                                240
                            )(else
                                (send gEgo:x)
                            )
                        )
)
                    y(162)
                )
            )
            (case 35
                (send gEgo:
                    x(300)
                    y(+ horizon (send gEgo:yStep))
                )
            )
            (case 40
                (send gEgo:
                    x(5)
                    y(160)
                )
            )
            (case 50
                (send gEgo:
                    x(315)
                    y(160)
                )
            )
            (case 60
                (send gEgo:
                    y(189)
                    setMotion(MoveTo (send gEgo:x) 188)
                )
            )
            (case 72
                (gear1:
                    init()
                    stopUpd()
                )
                (gear2:
                    init()
                    stopUpd()
                )
                (flap:
                    init()
                    stopUpd()
                )
                proc0_2()
                (self:setScript(egoClimbsDown))
            )
            (default 
                (send gEgo:
                    loop(2)
                    posn(160 162)
                )
            )
        )
        (lightningScript:start(1))
        (lightning1:
            init()
            hide()
            setScript(lightningScript)
        )
        (thunder:init())
        (if (proc0_6(0))
            Load(rsPIC 46)
            Load(rsSCRIPT 964)
            proc958_0(128 7 13)
            proc958_0(132 109 158 136 105 159 888)
            (shipPoly:
                points(@local1)
                size(27)
            )
            (compartmentPoly:
                points(@local57)
                size(5)
            )
            (cockpitPoly:
                points(@local67)
                size(6)
            )
            (shipFeature:init())
            (compartmentFeature:init())
            (cockpitFeature:init())
            (self:horizon(140))
            (send global2:addObstacle((send ((Polygon:new())):
                    type(2)
                    init(207 0 207 148 276 153 273 164 251 165 246 175 206 175 193 171 147 172 141 178 103 178 81 170 89 165 45 154 0 154 0 0)
                    yourself()
                )
))
            (send gEgo:
                setLoop(-1)
                illegalBits(0)
            )
            proc958_0(128 7 45)
            (gear1:
                init()
                stopUpd()
            )
            (gear2:
                init()
                stopUpd()
            )
            (flap:
                init()
                stopUpd()
            )
        )
        (self:drawPic(45))
        (if (proc0_6(0) or (== global12 72))
            (self:overlay(46 0))
        )
        (theRubble:init())
        (theRightBldg:init())
        (theLeftBldg:init())
        (theBackBldgs:init())
        (theStreet:init())
        (theArea:init())
        (self:setRegions(701))
        (super:init())
        (self:setRegions(705))
        (send gEgo:init())
        = picture 45
        (if (<> global12 72)
            proc0_3()
        )
    )


    (method (doit)
        (super:doit())
        (if (not proc0_6(0) or (send global2:script))
            0
        )(else
            (if ((not 
            (if (< 155 (send gEgo:y))
                (< (send gEgo:y) 185)
            )
 or (> (send gEgo:x) 250)) or (< local0 0))
                (send global2:setScript(shootEgo))
            )(else
                = local0 (- local0 1)
            )
        )
    )


    (method (newRoom param1)
        (if (== param1 30)
            (if (< (send gEgo:x) 80)
                = param1 25
            )(else
                (if (> (send gEgo:x) 240)
                    = param1 35
                )
            )
        )
        (super:newRoom(param1))
    )

)
(instance enterScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    x(65531)
                    y(160)
                    setMotion(MoveTo 10 160 self)
                )
            )
            (case proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance lightningScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = seconds Random(10 20)
            )
            (case 1
                (self:start(0))
                = seconds Random(3 6)
            )
            (case 2
                (send client:
                    show()
                    setCel(0)
                    setCycle(ForwardCounter Random(1 3) self)
                )
            )
            (case 3
                (thunder:play())
                (send client:hide())
                = cycles 15
            )
            (case 4
                (self:init())
            )
        )
    )

)
(instance thunder of Sound
    (properties
        number 149
        priority 13
    )
)
(instance egoHides of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send global2:horizon(0))
                (send gEgo:setMotion(PolyPath 132 150 self))
            )
            (case 1
                (send gEgo:
                    posn(137 142)
                    view(45)
                    loop(3)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 2
                proc0_11(43 5)
                (send gEgo:
                    hide()
                    dispose()
                )
                = seconds 4
            )
            (case 3
                (send gLongSong:
                    number(107)
                    loop(1)
                    vol(127)
                    play()
                )
                = seconds 4
            )
            (case 4
                (send gLongSong2:
                    number(158)
                    loop(-1)
                    vol(127)
                    play()
                )
                (gear1:
                    setPri(11)
                    cycleSpeed(1)
                    setMotion(MoveTo (gear1:x) 104)
                    setCycle(End flap)
                )
                (gear2:
                    setPri(9)
                    setMotion(DPath 188 134 174 120 174 78 self)
                )
            )
            (case 5
                (send gLongSong2:
                    number(136)
                    loop(1)
                    vol(127)
                    play()
                )
                = seconds 3
            )
            (case 6
                (send global2:newRoom(72))
                (send client:setScript(0))
            )
        )
    )

)
(instance egoClimbsDown of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gEgo:
                    normal(0)
                    view(45)
                    loop(3)
                    cel(8)
                    x(137)
                    y(142)
                    setCycle(Beg self)
                )
            )
            (case 1
                proc0_9()
                (send gEgo:
                    normal(1)
                    view(0)
                    x(135)
                    y(164)
                    setCycle(Walk)
                    setMotion(MoveTo 157 172 self)
                )
            )
            (case 2
                (send gEgo:setMotion(PolyPath 160 250 self))
            )
            (case 3
                (send gEgo:dispose())
                (egoHides:start(2))
                (send global2:setScript(egoHides))
            )
        )
    )

)
(instance shootEgo of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (cop1:
                    init()
                    setCycle(Walk)
                    setMotion(MoveTo 310 (cop1:y) self)
                )
                (cop2:
                    init()
                    setCycle(Walk)
                    setMotion(PolyPath 0 (cop2:y))
                )
            )
            (case 1
                (cop1:
                    view(13)
                    cel(0)
                    setMotion(0)
                    setCycle(CT 4 1 self)
                )
            )
            (case 2
                proc0_2()
                (cop2:setMotion(0))
                (cop1:setCycle(End self))
                (if (< (cop1:x) (send gEgo:x))
                    localproc_0fca(- (cop1:y) 27 (cop1:x) - (send gEgo:y) 32 (send gEgo:x))
                )(else
                    localproc_0fca(- (send gEgo:y) 32 (send gEgo:x) - (cop1:y) 27 (cop1:x))
                )
            )
            (case 3
                5
                (send gEgo:)
            )
            (case 4
                (send gEgo:setCycle(CT 1 -1 self))
            )
            (case 5
                (send gEgo:setCycle(End self))
            )
            (case 6
                = seconds 4
            )
            (case 7
                proc0_10(8)
            )
        )
    )

)
(instance deathScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send global2:horizon(0))
                (send gEgo:setMotion(PolyPath 210 175 self))
            )
            (case 1
                (send gEgo:setMotion(MoveTo (send gEgo:x) 165 self))
            )
            (case 2
                (send gEgo:
                    view(45)
                    loop(4)
                    cel(0)
                    x(+ (send gEgo:x) 5)
                    y(- (send gEgo:y) 13)
                    setCycle(End self)
                )
            )
            (case 3
                (send gEgo:
                    hide()
                    dispose()
                )
                = seconds 3
            )
            (case 4
                Print("The young shuttle pilot, his seat suddenly humidified by your surprise entry, fires an errant pulseray shot.")
                (send gLongSong2:
                    number(105)
                    loop(1)
                    vol(127)
                    play()
                )
                = cycles 4
            )
            (case 5
                (send gLongSong2:
                    vol(85)
                    play()
                )
                = cycles 2
            )
            (case 6
                (send gLongSong2:
                    vol(55)
                    play()
                )
                = cycles 6
            )
            (case 7
                (send gLongSong2:
                    vol(25)
                    play()
                )
                = cycles 4
            )
            (case 8
                (send gLongSong2:
                    vol(5)
                    play()
                )
                = cycles 10
            )
            (case 9
                (send gLongSong2:stop())
                Print("The shot just misses you (lucky stiff) and then caroms off the reflective surfaces of the cabin interior. During the course of this event it does eventually manage to take you both out (perforated stiff).")
                proc0_10(8 28)
            )
        )
    )

)
(instance lightning1 of Prop
    (properties
        x 150
        y 48
        description "lightning"
        lookStr "Lightning strikes the large wart-shaped behemoth. Its distance away is great enough to demonstrate the travel time difference between light and sound."
        view 46
    )
)
(instance gear1 of Actor
    (properties
        x 132
        y 120
        description "landing gear"
        lookStr "This is a landing gear assembly. It currently supports the ship."
        view 45
        priority 13
        signal 26640
    )

    (method (doVerb param1 param2)
        (switch (param1)
            (case 2
                (if (proc0_6(0) and not (send global2:script))
                    (if (not script)
                        proc0_2()
                        (send global2:setScript(egoHides))
                    )(else
                        Print("You're starting to show your age.")
                    )
                )(else
                    (super:doVerb(param1))
                )
            )
            (case 3
                (switch (param2)
                    (case 1
                        Print("You examine your puny piece of rope and realize that it wouldn't be strong enough to hold this puppy to the ground.")
                    )
                )
            )
            (default 
                (super:doVerb(param1))
            )
        )
    )

)
(instance gear2 of Actor
    (properties
        x 194
        y 134
        description "landing gear"
        lookStr "This is a landing gear assembly. It currently supports the ship."
        view 45
        loop 1
        priority 9
        signal 26640
    )

    (method (doVerb param1 param2)
        (switch (param1)
            (case 2
                Print("You can't budge this.")
            )
            (case 3
                (switch (param2)
                    (case 1
                        Print("You examine your puny piece of rope and realize that it wouldn't be strong enough to hold this puppy to the ground.")
                    )
                )
            )
            (default 
                (super:doVerb(param1))
            )
        )
    )

)
(instance flap of Prop
    (properties
        x 141
        y 111
        description "flap"
        lookStr "This is the landing gear compartment flap."
        view 45
        loop 2
        priority 13
        signal 24592
    )

    (method (doVerb param1)
        (switch (param1)
            (case 2
                (if (proc0_6(0))
                    (if (not script)
                        proc0_2()
                        (send global2:setScript(egoHides))
                    )(else
                        Print("You're starting to show your age.")
                    )
                )(else
                    (super:doVerb(param1))
                )
            )
            (default 
                (super:doVerb(param1))
            )
        )
    )


    (method (cue)
        (if (cel)
            (flapSound:
                number(159)
                loop(1)
                vol(127)
                play()
            )
        )(else
            (self:setCycle(End self))
        )
    )

)
(instance flapSound of Sound
    (properties)
)
(instance cop1 of Actor
    (properties
        x 319
        y 175
        lookStr "Oh No! Sequel Police!"
        view 7
        loop 2
    )
)
(instance cop2 of Actor
    (properties
        x 330
        y 185
        lookStr "Oh No! Sequel Police!"
        view 7
    )
)
(instance theRubble of Feature
    (properties
        x 144
        y 99
        z 12
        nsBottom 200
        nsRight 320
        description "rubble"
        sightAngle 45
        onMeCheck 64
        lookStr "You see a rubble barrier to the north."
    )
)
(instance theRightBldg of Feature
    (properties
        nsBottom 200
        nsRight 320
        description "right building"
        onMeCheck 128
        lookStr "The relatively undamaged building shows no entrances."
    )
)
(instance theLeftBldg of Feature
    (properties
        nsBottom 200
        nsRight 320
        description "left building"
        onMeCheck 8192
        lookStr "A once-prosperous bank building stands partially wrecked and sealed shut."
    )
)
(instance theBackBldgs of Feature
    (properties
        nsBottom 200
        nsRight 320
        description "back buildings"
        onMeCheck 16
        lookStr "In the distance not-so-fortunate buildings barely stand in ruin."
    )
)
(instance theArea of Feature
    (properties
        nsBottom 200
        nsRight 320
        description "area"
        lookStr "You stand centrally located in perhaps the only debris-clear area on the surface of this city. This was a busy intersection of commerce when times were happier and life... well... just existed. An odd structure looms in the distance."
    )

    (method (doVerb param1 param2)
        (switch (param1)
            (case 3
                (send (ScriptID(705 4)):doVerb(param1 param2))
            )
            (default 
                (super:doVerb(param1))
            )
        )
    )

)
(instance shipFeature of Feature
    (properties
        x 160
        y 100
        description "ship"
        sightAngle 25
        lookStr "You look at the finely-sculpted ship. It looks to have been designed for atmospheric operation - probably used solely for patrol excursions."
    )

    (method (init)
        (super:init())
        (self:onMeCheck(shipPoly))
    )


    (method (doVerb param1 param2)
        (switch (param1)
            (case 2
                Print("Your pockets aren't big enough.")
            )
            (case 3
                (switch (param2)
                    (case 1
                        Print("You examine your puny piece of rope and realize that it wouldn't be strong enough to hold this puppy to the ground.")
                    )
                    (default 
                        (super:doVerb(param1))
                    )
                )
            )
            (case 11
                Print("The dust kicked up by the retros, the heavy stench of burning fuel, and the sharp smell of electricity make for a unique olfactory extravaganza.")
            )
            (case 10
                Print("You sear your tongue on the hot metal. Apparently it's only safe to touch the now-exposed area beneath the landing gear housing flap.")
            )
            (default 
                (super:doVerb(param1))
            )
        )
    )

)
(instance shipPoly of Polygon
    (properties)
)
(instance compartmentFeature of Feature
    (properties
        x 160
        y 189
        z 89
        description "compartment"
        sightAngle 25
        lookStr "This seems to be a relatively-spacious landing gear compartment. Wonder how cramped it gets in there when the gear is stowed."
    )

    (method (init)
        (super:init())
        (self:onMeCheck(compartmentPoly))
    )


    (method (doVerb param1 param2)
        (switch (param1)
            (case 2
                (gear1:doVerb(param1 param2))
            )
            (case 3
                Print("You don't want to put that in there. You might need it later.")
            )
            (default 
                (super:doVerb(param1))
            )
        )
    )

)
(instance compartmentPoly of Polygon
    (properties)
)
(instance cockpitFeature of Feature
    (properties
        x 207
        y 189
        z 64
        description "front compartment"
        sightAngle 25
        lookStr "This is where those militia-types enter and exit the shuttle."
    )

    (method (init)
        (super:init())
        (self:onMeCheck(cockpitPoly))
    )


    (method (doVerb param1)
        (if ((== param1 2) or (== param1 3))
            proc0_2()
            (send global2:setScript(deathScript))
        )(else
            (super:doVerb(param1))
        )
    )

)
(instance cockpitPoly of Polygon
    (properties)
)
(instance theStreet of Feature
    (properties
        nsBottom 200
        nsRight 320
        description "street"
        onMeCheck 2
        lookStr "I think we're looking at your basic surface transportation intersection."
    )

    (method (doVerb param1 param2)
        (switch (param1)
            (case 11
                Print("It doesn't exactly smell April-fresh.")
            )
            (case 10
                Print("It's not as big a taste sensation as other parts of the city.")
            )
            (case 3
                (send (ScriptID(705 4)):doVerb(param1 param2))
            )
            (default 
                (super:doVerb(param1))
            )
        )
    )

)
