(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "brain")
(use "SQRoom")
(use "Osc")
(use "PolyPath")
(use "Class_950_0")
(use "MoveFwd")
(use "n958")
(use "StopWalk")
(use "DPath")
(use "Rev")
(use "Sound")
(use "Cycle")
(use "PicView")
(use "Obj")
(script 150)


(local
    local0
    local1
    local2 = 10
    local3 = 15
    local4
    local5[8] = (161 189 186 154 120 91 87 118 )
    local13[45] = (119 107 80 67 61 79 107 126 2 2 122 99 2 3 122 99 2 2 122 99 2 3 122 99 2 2 122 99 2 3 122 99 2 2 122 99 2 3 122 99 2 2 122 99 32768 )

)
(procedure (localproc_0016 param1 param2 param3)
    (var temp0, temp1, temp2, temp3, temp4, temp5, temp6)
    (laserSound:play())
    = temp0 (send param1:x)
    = temp1 (- (send param1:y) 10)
    = temp2 (- proc999_2(temp1 param3) 1)
    = temp3 (+ proc999_3(temp1 param3) 1)
    = temp4 (- proc999_2(temp0 param2) 1)
    = temp5 (+ proc999_3(temp0 param2) 1)
    = temp6 Graph(7 temp2 temp4 temp3 temp5 1)
    Graph(4 temp1 temp0 param3 param2 global143 -1 -1)
    Graph(13 temp2 temp4 temp3 temp5 1)
    Wait(1)
    Wait(5)
    Graph(8 temp6)
    Graph(13 temp2 temp4 temp3 temp5 1)
    (if ((<> param2 (send gEgo:x)) or (<> param3 (- (send gEgo:y) 15)))
        (blast:
            x(param2)
            y(param3)
            init()
            setCycle(End blast)
        )
    )
)


(instance public rm150 of SQRoom
    (properties
        lookStr "This is Vohaul's chamber, where his dirtiest of deeds are set into motion.  The lit pedestal in the center towers jillions of feet above the floor.  Though relatively dark you can sense that this place is alive with raw energy."
        picture 150
        south 505
    )

    (method (init)
        proc958_0(128 522)
        proc958_0(128 150 550)
        Load(rsSCRIPT 151)
        (if (not (brain:formatting))
            proc958_0(132 118 120 119 121)
        )(else
            proc958_0(132 152)
        )
        (if (< (send gEgo:x) 160)
            (send gEgo:
                x(170)
                y(250)
                init()
            )
        )(else
            (send gEgo:
                x(325)
                y(235)
                init()
            )
        )
        (self:setRegions(704))
        (super:init())
        (brain:
            makePolygon(194 189 199 181 210 176 221 174 233 174 249 178 272 189)
            makePolygon(116 189 138 159 155 159 151 189)
            makePolygon(319 165 220 145 216 140 231 136 319 153)
        )
        (diskDrive:
            init()
            stopUpd()
        )
        (ladder:init())
        (overhang:init())
        (pedestal:init())
        (lOrb:init())
        (rOrb:init())
        (if ((brain:formatting))
            (lOrb:addToPic())
            (rOrb:addToPic())
        )
        (send gLongSong:fade())
        (self:setScript(rescueScript))
    )


    (method (doit)
        (super:doit())
        (if (script)
        )(else
            (if (proc0_5(gEgo 4))
                (self:setScript(fallScript))
            )(else
                (if (proc0_5(gEgo 2))
                    (self:setScript(climbScript))
                )
            )
        )
    )


    (method (dispose)
        DisposeScript(151)
        DisposeScript(152)
        (super:dispose())
    )


    (method (notify param1)
        (switch (param1)
            (case -1
                = local4 1
            )
            (default 
                = local1 param1
            )
        )
    )

)
(instance rescueScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if ((send gCast:contains(ScriptID(704 1))))
                    (send ((send (ScriptID(704 1)):body)):dispose())
                    (send (ScriptID(704 1)):dispose())
                )
                (if ((send gCast:contains(ScriptID(704 2))))
                    (send ((send (ScriptID(704 2)):body)):dispose())
                    (send (ScriptID(704 2)):dispose())
                )
                (send gLongSong2:
                    number(848)
                    vol(127)
                    loop(1)
                    play()
                )
                (RogerJr:
                    init()
                    setCycle(Fwd)
                )
                (send gEgo:
                    setPri(-1)
                    setLoop(-1)
                )
                (if (== (send gEgo:x) 170)
                    (send gEgo:setMotion(PolyPath 170 170 self))
                )(else
                    (send gEgo:setMotion(PolyPath 260 170 self))
                )
            )
            (case 1
                (if (not (brain:formatting))
                    (lOrb:setScript(laserScript))
                    (self:dispose())
                )(else
                    proc0_11(79 5)
                    (send gLongSong2:stop())
                    (RogerJr:
                        posn(133 94)
                        setLoop(1)
                        setCel(0)
                        cycleSpeed(1)
                        setCycle(End)
                    )
                    (bridge:
                        init()
                        setMotion(MoveTo 180 153 self)
                    )
                    (bridgeSound:play())
                )
            )
            (case 2
                (bridgeSound:stop())
                (brain:
                    makePolygon(123 159 123 127 166 127 180 150 155 159)
                    makePolygon(218 145 195 148 175 124 202 109 228 135 216 140)
                )
                (send gEgo:setMotion(PolyPath 156 118 self))
            )
            (case 3
                (bridge:setMotion(MoveTo 193 176 self))
                (bridgeSound:play())
            )
            (case 4
                (bridge:dispose())
                (bridgeSound:stop())
                (RogerJr:
                    setLoop(2)
                    setCel(0)
                    setCycle(End self)
                )
                (diskDrive:setMotion(MoveTo 120 98 diskDrive))
            )
            (case 5
            )
            (case 6
                (RogerJr:
                    view(550)
                    setLoop(0)
                    setCel(0)
                    setPri(9)
                    posn(125 94)
                    setCycle(CT 4 1 self)
                )
            )
            (case 7
                = seconds 2
            )
            (case 8
                Print("Hee, hee, hee! Hello again, Roger.  It's me - your old friend Sludge Vohaul.  I've taken the liberty of borrowing your son's body.  I had to remove him first to make room for my mental self.  His is on this disk.  I must say, it is most enjoyable to be in a young, healthy body - even if it is from YOUR blood line.")
                Print("In fact, I like it so much I think I'll keep it.  I guess we'll have no use for this anymore.")
                = seconds 2
            )
            (case 9
                (RogerJr:setCycle(End self))
                (disk:
                    init()
                    setCycle(Fwd)
                    setMotion(DPath 88 61 53 65 20 98 65531 133 disk)
                )
            )
            (case 10
                (RogHead:
                    posn(+ (RogerJr:x) 8 - (RogerJr:y) 31)
                    init()
                    setCycle(Fwd)
                )
                = cycles 10
            )
            (case 11
                (RogerJr:
                    view(525)
                    setLoop(0)
                    setPri(-1)
                    cycleSpeed(0)
                    setCycle(Rev)
                    setMotion(MoveTo local5[4] local13[(RogHead:dispose())] self)
                )
                (diskDrive:setMotion(MoveTo 120 110 diskDrive))
            )
            (case 12
            )
            (case 13
                Print("Now it's time to settle things once and for all.  You'd better be careful, though.  Keep this in mind - if I die while in this body that disk will be useless.  Your son will NEVER draw another breath and, if you don't defend yourself you will never live to buff another helmet!")
                Print("Come on - show me what you've got, mop jockey!")
                Animate((send gCast:elements) 0)
                (RogerJr:
                    view(527)
                    setCycle(Walk)
                )
                (send gEgo:
                    view(526)
                    setCycle(Walk)
                )
                (self:setScript(ScriptID(151 0) self))
            )
            (case 14
                (self:setScript(ScriptID(151 1) self))
            )
            (case 15
                (self:dispose())
            )
        )
    )

)
(instance laserSound of Sound
    (properties
        number 106
    )
)
(instance laserScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_3()
                = seconds 5
            )
            (case 1
                localproc_0016(lOrb - (send gEgo:x) 25 159)
                = cycles 20
            )
            (case 2
                localproc_0016(rOrb + (send gEgo:x) 25 143)
                = cycles 20
            )
            (case 3
                localproc_0016(lOrb - (send gEgo:x) 15 161)
                = cycles 20
            )
            (case 4
                localproc_0016(rOrb + (send gEgo:x) 15 150)
                = cycles 20
            )
            (case 5
                localproc_0016(lOrb - (send gEgo:x) 5 160)
                = cycles 20
            )
            (case 6
                localproc_0016(rOrb + (send gEgo:x) 5 158)
                = cycles 20
            )
            (case 7
                localproc_0016(lOrb (send gEgo:x) - (send gEgo:y) 15)
                = cycles 1
            )
            (case 8
                (send gEgo:
                    view(511)
                    setLoop(1)
                    setCel(0)
                    setCycle(End self)
                )
            )
            (case 9
                proc0_10(8 30)
            )
        )
    )

)
(instance climbScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (if ((send gEgo:has(14)))
                    Print("You don't really want to go down there AGAIN...")
                    = register 1
                    (send gEgo:setMotion(MoveTo 100 115 self))
                )(else
                    (send gEgo:setMotion(MoveTo 84 115 self))
                )
            )
            (case 1
                (if (register)
                    proc0_3()
                    (self:dispose())
                )(else
                    (send gEgo:setHeading(270 self))
                )
            )
            (case 2
                (send gEgo:
                    view(551)
                    setLoop(2)
                    setCel(0)
                    cycleSpeed(1)
                    setCycle(End self)
                )
            )
            (case 3
                (send gEgo:
                    posn(77 144)
                    setLoop(0)
                    setCel(0)
                    setCycle(Fwd)
                    setMotion(MoveTo 98 245 self)
                )
            )
            (case 4
                (send gEgo:get(14))
                = seconds 5
            )
            (case 5
                (send gEgo:
                    setCycle(Rev)
                    setMotion(MoveTo 77 144 self)
                )
            )
            (case 6
                (send gEgo:
                    posn(84 115)
                    setLoop(2)
                    setCel(2)
                    setCycle(Beg self)
                )
            )
            (case 7
                (send gEgo:
                    view(3)
                    setLoop(-1)
                    cycleSpeed(0)
                    setCycle(StopWalk 510)
                    setMotion(MoveTo 100 115 self)
                )
            )
            (case 8
                proc0_3()
                proc0_11(64 5)
                (self:dispose())
            )
        )
    )

)
(instance fallScript of Script
    (properties)

    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:setMotion(MoveFwd 12 self))
            )
            (case 1
                (send gEgo:setHeading(180))
                = cycles 8
            )
            (case 2
                Print("Dang!")
                (if (< (send gEgo:y) 95)
                    = temp0 1
                )(else
                    (if (< (send gEgo:x) 95)
                        = temp0 12
                    )(else
                        = temp0 3
                    )
                )
                (send gEgo:
                    setCycle(0)
                    setStep((send gEgo:xStep) 19)
                    setPri(temp0)
                    setMotion(MoveTo (send gEgo:x) 300 self)
                )
            )
            (case 3
                proc0_10()
            )
        )
    )

)
(instance jrFreeScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (brain:formatting(0))
                (RogerJr:
                    posn(133 91)
                    setLoop(1)
                    setCel(0)
                    cycleSpeed(1)
                    setCycle(End self)
                )
            )
            (case 1
                = seconds 3
            )
            (case 2
                (RogerJr:
                    setLoop(2)
                    setCel(0)
                    setCycle(End self)
                )
            )
            (case 3
                (if (local4)
                    proc0_10(0 11)
                )(else
                    (send gLongSong:
                        number(870)
                        vol(127)
                        loop(-1)
                        flags(1)
                        play()
                        changeState()
                    )
                    = cycles 2
                )
            )
            (case 4
                Print("Thanks for saving me.  I thought I was a goner.")
                Print("Follow me.  There are many things we need to talk about.")
                (send global2:newRoom(556))
            )
        )
    )

)
(instance driveScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gEgo:setMotion(PolyPath 111 99 self))
            )
            (case 1
                (send (ScriptID(152 0)):
                    init()
                    addToPic()
                )
                (self:dispose())
            )
        )
    )

)
(instance public RogerJr of Actor
    (properties
        x 127
        y 39
        description "Roger Jr."
        lookStr "It's Roger Jr!"
        view 522
        priority 4
        signal 16400
    )

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


    (method (dispose)
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (if (local1 and proc255_5(self pEvent))
            (send (ScriptID(151 0)):handleEvent((send pEvent:
                    type(64)
                    message(1)
                )
))
        )(else
            (super:handleEvent(pEvent))
        )
    )

)
(instance RogHead of Prop
    (properties
        view 550
        loop 1
        priority 14
        signal 16400
    )
)
(instance driveSound of Sound
    (properties)
)
(instance public diskDrive of Actor
    (properties
        x 120
        y 110
        description "disk drive"
        lookStr "It's a disk drive."
        view 522
        loop 3
        priority 5
        signal 18448
        illegalBits 0
    )

    (method (doVerb param1 param2 param3)
        (switch (param1)
            (case 3
                (if (== param2 14)
                    (if ((send gAddToPics:contains(ScriptID(152 0))))
                        (send (ScriptID(152 0)):doVerb(param1 param2 rest param3))
                    )(else
                        (if (== param2 14)
                            (send ((send gInv:at(14))):owner(self))
                            (send gEgo:put(14 gNumber))
                            proc0_11(65 5)
                        )
                        (self:setScript(driveScript))
                    )
                )
            )
            (case 1
                Print("It's a disk drive unit.")
            )
            (default 
                (super:doVerb(param1 param2 rest param3))
            )
        )
    )


    (method (cue)
        (driveSound:
            number(877)
            play()
        )
        (if (== y 98)
            (self:setCycle(Fwd))
        )(else
            (self:stopUpd())
        )
        (if (not (send global2:script))
            (send global2:setScript(jrFreeScript))
        )(else
            (if ((rescueScript:script))
                (send ((rescueScript:script)):cue())
            )(else
                (rescueScript:cue())
            )
        )
    )


    (method (setMotion param1)
        (driveSound:
            number(876)
            play()
        )
        (super:setMotion(rest param1))
    )

)
(instance ladder of Feature
    (properties
        x 83
        y 149
        nsTop 109
        nsLeft 66
        nsBottom 189
        nsRight 100
        description "ladder"
        sightAngle 90
        lookStr "The ladder leads down to the floor far below."
    )

    (method (doVerb param1 param2)
        (switch (param1)
            (case 2
                (send gEgo:setMotion(PolyPath 90 115))
            )
            (default 
                (super:doVerb(param1 rest param2))
            )
        )
    )

)
(instance disk of Actor
    (properties
        x 88
        y 61
        yStep 7
        view 550
        loop 2
        priority 14
        signal 2064
        xStep 7
    )

    (method (cue)
        (self:dispose())
    )

)
(instance bridgeSound of Sound
    (properties
        number 152
    )
)
(instance bridge of Actor
    (properties
        x 193
        y 176
        view 522
        loop 4
        priority 2
        signal 18448
        illegalBits 0
    )
)
(instance blast of Prop
    (properties
        view 28
        signal 24576
    )

    (method (cue)
        (super:cue())
        (self:dispose())
    )

)
(instance lOrbZap of Sound
    (properties)
)
(instance rOrbZap of Sound
    (properties)
)
(instance lOrb of Prop
    (properties
        x 47
        y 123
        description "left orb"
        sightAngle 90
        view 151
        priority 8
    )

    (method (doit)
        (super:doit())
        (if (local2 and not --local2)
            (if (< Random(1 10) 5)
                = loop 0
            )(else
                = loop 2
            )
            (if (< Random(1 10) 5)
                (lOrbZap:
                    number(
                        (if (loop)
                            120
                        )(else
                            118
                        )
)
                    play()
                )
                (self:setCycle(Osc 1 self))
            )(else
                (lOrbZap:
                    number(
                        (if (loop)
                            120
                        )(else
                            118
                        )
)
                    play()
                )
                (self:setCycle(End self))
            )
        )
    )


    (method (doVerb param1 param2)
        (switch (param1)
            (case 1
                Print(
                    (if (cycler)
                        "The orbs of fury crackle and sizzle with raw energy."
                    )(else
                        "The orbs just seem to hover alongside the platform."
                    )
)
            )
            (default 
                (super:doVerb(param1 rest param2))
            )
        )
    )


    (method (cue)
        = local2 Random(20 50)
        (lOrbZap:stop())
        (self:stopUpd())
    )

)
(instance rOrb of Prop
    (properties
        x 230
        y 87
        description "right orb"
        sightAngle 90
        view 151
        loop 1
        priority 8
    )

    (method (doit)
        (super:doit())
        (if (local3 and not --local3)
            (if (< Random(1 10) 5)
                = loop 1
            )(else
                = loop 3
            )
            (if (< Random(1 10) 5)
                (rOrbZap:
                    number(
                        (if (== loop 3)
                            121
                        )(else
                            119
                        )
)
                    play()
                )
                (self:setCycle(Osc 1 self))
            )(else
                (rOrbZap:
                    number(
                        (if (== loop 3)
                            121
                        )(else
                            119
                        )
)
                    play()
                )
                (self:setCycle(End self))
            )
        )
    )


    (method (doVerb param1 param2)
        (switch (param1)
            (case 1
                Print(
                    (if (cycler)
                        "The orbs of fury crackle and sizzle with raw energy."
                    )(else
                        "The orbs just seem to hover alongside the platform."
                    )
)
            )
            (default 
                (super:doVerb(param1 rest param2))
            )
        )
    )


    (method (cue)
        = local3 Random(20 50)
        (rOrbZap:stop())
        (self:stopUpd())
    )

)
(instance overhang of Feature
    (properties
        description "overhang"
        lookStr "This is the top half of an odd I/O unit.  It also provides lighting for the area."
    )

    (method (onMe param1)
        return == OnControl(2 (send param1:x) (send param1:y)) 16384
    )

)
(instance pedestal of Feature
    (properties
        description "pedestal"
        lookStr "The large pedestal standing in the center of this chamber seems to be some sort of huge I/O unit for the Super Computer."
    )

    (method (doVerb param1 param2)
        (switch (param1)
            (case 10
                Print("Even standing on your tiptoes, you'd never be able to reach that with your tongue.")
            )
            (case 11
                Print("It smells like a desperate, sweaty maintenance engineer has been walking around here.")
            )
            (default 
                (super:doVerb(param1 rest param2))
            )
        )
    )


    (method (onMe param1)
        return == OnControl(2 (send param1:x) (send param1:y)) 4
    )

)
