(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "RegionPath")
(use "ForwardCounter")
(use "n958")
(use "Grooper")
(use "n982")
(use "Sound")
(use "Cycle")
(use "Game")
(use "PicView")
(use "Obj")
(script 701)


(local
    cyborgLoop = 65535
    local1
    local2
    local3[74] = (0 0 0 0 314 65462 278 120 214 195 152 321 152 321 314 65464 314 65464 240 178 210 333 210 333 314 65464 314 65464 220 165 327 320 327 320 65463 65453 65463 65453 76 183 6 296 6 296 65471 94 65471 94 55 191 133 320 133 320 65512 14 65512 14 70 191 164 298 164 298 65512 180 65512 180 160 160 100 160 100 160 )
    local77[129] = (32767 30 100 500 200 500 32767 35 0 132 24 76 79 57 46 108 100 250 32767 50 0 65 220 75 218 73 40 128 30 250 32767 65 0 100 15 100 103 125 145 151 65531 173 32767 60 319 157 239 175 239 181 65531 150 32767 55 319 100 238 100 295 65535 32767 40 221 250 195 97 79 78 278 35 302 65535 32767 25 91 219 210 145 297 250 32767 40 310 55 270 150 285 250 32767 55 319 65 228 68 109 163 125 145 140 163 242 83 325 83 32767 60 0 140 325 140 32767 65 0 170 60 160 65531 95 32767 50 101 219 90 96 101 92 65531 103 32768 )
    local206[48] = (65534 65490 1 0 0 0 8 65492 1 0 0 0 13 65493 3 11 65491 3 5 65493 3 9 65493 3 65533 65494 1 0 0 0 65525 65493 2 65528 65493 2 65522 65493 2 65527 65493 2 65530 65490 1 )
    local254[16] = (0 60 65506 30 65476 0 65506 65506 0 65476 30 65506 60 0 30 30 )

)
(procedure (localproc_11dc param1)
    return 
        (if (>= param1 22)
            return - param1 22
        )(else
            return - 360 (- 22 param1)
        )
)


(class street of Rgn
    (properties
        script 0
        number 0
        timer 0
        keep 0
        initialized 0
        lookStr 0
        gracePeriod 4200
    )

    (method (init param1)
        (super:init(rest param1))
        = local1 Random(500 1000)
        proc958_0(128 26)
        (streetSoundFX:init())
        (if (not Btest(0))
            proc958_0(128 25 51)
            (cyborg:
                init()
                setLoop(Grooper)
                setCycle(Walk)
                setMotion(cyborgPath)
            )
        )
    )


    (method (doit)
        (super:doit())
        (if (gracePeriod)
            --gracePeriod
        )
        (if ((> local1 0) and not (deathDroid:script))
            = local1 (- local1 1)
        )(else
            = local1 Random(500 1000)
            (if (((((((not gracePeriod and not (send global2:script)) and not Btest(0)) and (< (deathDroid:z) 100)) and not (deathDroid:script)) and (<> gNumber 45)) and (<> gNumber 30)) and (<> gNumber 60))
                (deathDroid:
                    init()
                    setCycle(turnCycle)
                    setScript(lookScript)
                )
                (send gLongSong2:
                    number(21)
                    vol(127)
                    loop(-1)
                    flags(1)
                    play()
                )
                (send gLongSong:stop())
            )
        )
    )


    (method (newRoom param1 param2)
        = keep proc999_5(param1 25 30 35 40 45 50 55 60 65)
        = initialized 0
        (if (== (send gLongSong2:number) 21)
            (send gLongSong2:fade())
        )
        (if (== (send gLongSong:prevSignal) -1)
            (send gLongSong:
                number(801)
                loop(-1)
                vol(0)
                flags(1)
                playBed()
                fade(127 15 10 0)
            )
        )
        (super:newRoom(param1 rest param2))
    )

)
(instance public deathDroid of Actor
    (properties
        z 45
        description "Droid-O-Death"
        lookStr "The Droid-O-Death, somewhat resembling a stripped down Maytag washer, hovers 15 feet above the surface of the street."
        yStep 5
        view 25
        priority 14
        signal 26640
        illegalBits 0
        xStep 5
    )

    (method (isNotHidden)
        return not proc982_0(self)
    )

)
(instance public cyborg of Actor
    (properties
        description "cyborg"
        sightAngle 45
        lookStr "This is the only form of actual life that you've seen down here! It's not a very good specimen though. Its clothes are tattered and a grotesque metal contraption is clamped to its head which serves to hold the eyelids permanently open."
        yStep 1
        view 51
        signal 24576
        illegalBits 0
        xStep 2
    )

    (method (doit param1)
        (super:doit(rest param1))
        (if ((deathDroid:script))
            (cyborg:setMotion(0))
            (if (== cyborgLoop -1)
                = cyborgLoop (cyborg:loop)
            )
            proc0_13(cyborg deathDroid)
        )
        (if ((((((not (cyborg:z) and (<> (send global2:script) cyborgScreams)) and (<> (send global2:script) ScriptID(812 0))) and (< (cyborg:distanceTo(gEgo)) 60)) and (<> (send gEgo:onControl(1)) 256)) and not (deathDroid:script)) and ((< Abs((- GetAngle((cyborg:x) (cyborg:y) (send gEgo:x) (send gEgo:y)) (cyborg:heading))) 49) or (< (cyborg:distanceTo(gEgo)) 30)))
            (if (((== gNumber 50) and (== (send global2:script) ScriptID(50 1))) and (== (send gEgo:view) 50))
                (cyborg:setMotion(0))
                proc0_13(cyborg gEgo)
            )(else
                proc0_2()
                (send gEgo:setMotion(0))
                (send global2:setScript(cyborgScreams))
            )
        )
    )


    (method (doVerb param1)
        (switch (param1)
            (case 4
                Print("He seems to be unaware of your existence, almost as though he is controlled by some other consciousness.")
            )
            (case 11
                Print("As a result of being persistently downwind of the cyborg you are very aware that it smells like a slice of luncheon meat that's been walking around in the sun too long.")
            )
            (case 10
                Print("Not with your tongue!")
            )
            (default 
                (super:doVerb(param1))
            )
        )
    )


    (method (isNotHidden)
        return not proc982_0(self)
    )

)
(instance public cyborgPath of RegionPath
    (properties
        theRegion 701
    )

    (method (nextRoom param1)
        (if ((== gNumber (self:at((+ value 2)))) and (< GetDistance((self:at((+ value 3))) (self:at((+ value 4))) (send gEgo:x) (send gEgo:y)) 50))
            (do 
                = value (- value 2)
            ) while (not == (self:at((+ 1 value))) 32767)
        )
        (super:nextRoom(rest param1))
    )


    (method (at param1)
        return local77[param1]
    )

)
(instance lookScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = local2 
                    (switch (gNumber)
                        (case 25
                            4
                        )
                        (case 35
                            54
                        )
                        (case 40
                            14
                        )
                        (case 50
                            44
                        )
                        (case 55
                            24
                        )
                        (case 60
                            64
                        )
                        (case 65
                            34
                        )
                    )
                (self:register(
                    (if (> (send gEgo:y) 120)
                        -1
                    )(else
                        1
                    )
))
                (deathDroid:
                    x(local3[+ (+ local2 (* 4 register)) 4])
                    y(local3[+ (+ local2 (* 4 register)) 5])
                    setCycle(turnCycle)
                    setMotion(MoveTo local3[+ (+ local2 (* 2 register)) 4] local3[+ (+ local2 (* 2 register)) 5] self)
                )
            )
            (case 1
                (deathDroid:setMotion(MoveTo local3[(+ local2 4)] local3[(+ local2 5)] self))
            )
            (case 2
                (if ((((not (send global2:script) or (== (send global2:script) cyborgScreams)) or (== (send global2:script) ScriptID(705 2))) and (<> (send gEgo:onControl(1)) 256)) or (== (send global2:script) cyborgScreams))
                    (deathDroid:
                        cycleSpeed(2)
                        setScript(droidShoots)
                    )
                )(else
                    (deathDroid:
                        cycleSpeed(2)
                        setCycle(End self)
                    )
                    proc0_11(45 5)
                )
            )
            (case 3
                (deathDroid:
                    loop(0)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 4
                (if (not (send global2:script) and (<> (send gEgo:onControl(1)) 256))
                    (deathDroid:setScript(droidShoots))
                )(else
                    = cycles 1
                )
            )
            (case 5
                (deathDroid:setCycle(CT 
                    (if (== register -1)
                        (switch (gNumber)
                            (case 25
                                5
                            )
                            (case 35
                                3
                            )
                            (case 40
                                5
                            )
                            (case 50
                                3
                            )
                            (case 55
                                4
                            )
                            (case 65
                                4
                            )
                        )
                    )(else
                        (switch (gNumber)
                            (case 25
                                1
                            )
                            (case 35
                                7
                            )
                            (case 40
                                1
                            )
                            (case 50
                                7
                            )
                            (case 55
                                1
                            )
                            (case 65
                                7
                            )
                        )
                    )
 -1 self))
            )
            (case 6
                (deathDroid:
                    cycleSpeed(0)
                    setCycle(turnCycle)
                    setMotion(MoveTo local3[+ (+ local2 (* 2 (* register -1))) 4] local3[+ (+ local2 (* 2 (* register -1))) 5] self)
                )
            )
            (case 7
                (deathDroid:setMotion(MoveTo local3[(+ (+ local2 (* 4 (* register -1))) 4)] local3[(+ (+ local2 (* 4 (* register -1))) 5)] self))
                (cyborg:setLoop(-1))
                (send gLongSong2:fade())
            )
            (case 8
                (deathDroid:dispose())
                (send gLongSong:
                    number(801)
                    loop(-1)
                    vol(0)
                    playBed()
                    flags(1)
                    fade(127 15 10 0)
                )
                (cyborg:
                    loop(cyborgLoop)
                    setLoop(Grooper)
                    setCycle(Walk)
                    setMotion(cyborgPath)
                )
                = cyborgLoop -1
                (lookScript:start(0))
                proc0_3()
                (send client:setScript(0))
            )
        )
    )

)
(instance public droidShoots of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (deathDroid:setCycle(CT proc999_2(7 (/ (* GetAngle((deathDroid:x) (deathDroid:y) (send gEgo:x) (send gEgo:y)) 4) 180)) -1 self))
            )
            (case 1
                (if (< (deathDroid:distanceTo(gEgo)) 30)
                    (if ((< 2 (deathDroid:cel)) and (< (deathDroid:cel) 7))
                        (deathDroid:setPri(13))
                    )
                    (deathDroid:
                        xStep(10)
                        yStep(10)
                        setCycle(0)
                        setMotion(MoveTo + (deathDroid:x) local254[(* (deathDroid:cel) 2)] + (deathDroid:y) local254[(+ (* (deathDroid:cel) 2) 1)] self)
                    )
                )(else
                    (deathDroid:setCycle(0))
                    = cycles 2
                )
            )
            (case 2
                proc0_2()
                = cycles 2
            )
            (case 3
                proc0_2()
                proc0_13(gEgo deathDroid)
                (send gEgo:setMotion(0))
                = cycles 2
            )
            (case 4
                proc0_2()
                (gunFire1:
                    init()
                    x(+ (deathDroid:x) local206[(* (deathDroid:cel) 6)])
                    y(+ (deathDroid:y) local206[(+ (* (deathDroid:cel) 6) 1)])
                    loop(local206[+ (* (deathDroid:cel) 6) 2])
                    setPri(
                        (if ((< 2 (deathDroid:cel)) and (< (deathDroid:cel) 7))
                            14
                        )(else
                            12
                        )
)
                    setCycle(End)
                )
                (if ((< 1 local206[(+ (* (deathDroid:cel) 6) 2)]) and (< local206[(+ (* (deathDroid:cel) 6) 2)] 4))
                    (gunFire2:
                        init()
                        x(+ (deathDroid:x) local206[(+ (* (deathDroid:cel) 6) 3)])
                        y(+ (deathDroid:y) local206[(+ (* (deathDroid:cel) 6) 4)])
                        loop(local206[+ (* (deathDroid:cel) 6) 5])
                        setPri(
                            (if ((< 2 (deathDroid:cel)) and (< (deathDroid:cel) 7))
                                14
                            )(else
                                12
                            )
)
                        setCycle(End)
                    )
                )
                = cycles 3
            )
            (case 5
                proc0_2()
                (streetSoundFX:
                    number(106)
                    loop(1)
                    play()
                )
                = cycles 3
            )
            (case 6
                (streetSoundFX:play())
                (if (IsObject(ScriptID(705 3)))
                    (send (ScriptID(705 3)):dispose())
                )
                proc0_2()
                (send gLongSong:
                    number(135)
                    loop(-1)
                    vol(127)
                    flags(0)
                    play()
                )
                (send gEgo:
                    view(26)
                    normal(0)
                    loop(
                        (switch ((send gEgo:loop))
                            (case 4
                                0
                            )
                            (case 5
                                1
                            )
                            (case 6
                                0
                            )
                            (case 7
                                1
                            )
                            (default 
                                (send gEgo:loop)
                            )
                        )
)
                    cel(0)
                    cycleSpeed(0)
                    setCycle(CT 1 1)
                    setMotion(0)
                )
                = cycles 3
            )
            (case 7
                (streetSoundFX:play())
                proc0_2()
                (gunFire1:dispose())
                (gunFire2:dispose())
                (send gEgo:setCycle(Beg self))
            )
            (case 8
                (send gEgo:setCycle(CT 1 1 self))
            )
            (case 9
                (send gEgo:setCycle(Beg self))
            )
            (case 10
                (send gEgo:setCycle(CT 1 1 self))
            )
            (case 11
                (send gEgo:setCycle(Beg self))
            )
            (case 12
                (send gEgo:setCycle(End self))
            )
            (case 13
                (send gLongSong:stop())
                = seconds 3
                (send gLongSong2:fade())
            )
            (case 14
                proc0_10(8)
            )
        )
    )

)
(instance public cyborgScreams of Script
    (properties)

    (method (doit)
        (super:doit())
        (if ((== state 7) and (== (streetSoundFX:prevSignal) -1))
            (self:cue())
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_13(cyborg gEgo)
                proc0_13(gEgo cyborg)
                = cycles 3
            )
            (case 1
                (send gIconBar:disable())
                = cycles 1
            )
            (case 2
                (send (ScriptID(705 1)):dispose())
                Load(rsSOUND 114)
                (cyborg:
                    hide()
                    setMotion(0)
                )
                (deathDroid:mover(0))
                (send gEgo:hide())
                DrawPic(31 30)
                (send global2:curPic(31))
                (mouth:init())
                = cycles 1
            )
            (case 3
                (send gLongSong:stop())
                (send gLongSong2:
                    number(829)
                    loop(-1)
                    vol(127)
                    flags(1)
                    play()
                )
                (send gIconBar:enable())
                proc0_2()
                = seconds 3
            )
            (case 4
                (mouth:setCycle(ForwardCounter 9 self))
            )
            (case 5
                (mouth:
                    posn(142 106)
                    setLoop(1)
                    setCycle(ForwardCounter 7 self)
                )
            )
            (case 6
                (mouth:
                    posn(152 104)
                    setLoop(2)
                    setCycle(ForwardCounter 5 self)
                )
            )
            (case 7
                (streetSoundFX:
                    number(114)
                    loop(1)
                    flags(1)
                    play()
                )
                (hand:init())
                (mouth:
                    posn(151 127)
                    setLoop(3)
                    setCycle(Fwd)
                )
            )
            (case 8
                (send gIconBar:disable())
                = cycles 1
            )
            (case 9
                (hand:dispose())
                (mouth:dispose())
                (cyborg:show())
                (send gEgo:show())
                DrawPic(gNumber)
                (send global2:curPic(gNumber))
                UnLoad(132 114)
                UnLoad(129 31)
                proc958_0(128 25 26)
                proc958_0(132 106 135)
                = cycles 1
            )
            (case 10
                (send gIconBar:enable())
                (send gLongSong2:
                    number(21)
                    vol(127)
                    loop(-1)
                    flags(1)
                    play()
                )
                (send gLongSong:stop())
                (deathDroid:
                    init()
                    setCycle(turnCycle)
                    setScript(lookScript)
                )
                (cyborg:setMotion(0))
            )
            (case 11
                0
            )
        )
    )

)
(instance mouth of Actor
    (properties
        x 153
        y 106
        view 31
        signal 24576
    )
)
(instance hand of View
    (properties
        x 118
        y 189
        view 31
        loop 4
        signal 24576
    )
)
(instance gunFire1 of Prop
    (properties)
)
(instance gunFire2 of Prop
    (properties)
)
(instance turnCycle of Fwd
    (properties)

    (method (nextCel)
        return + (/ (* localproc_11dc((send client:heading)) 4) 180) 1
    )

)
(instance streetSoundFX of Sound
    (properties
        number 106
    )
)
