(include "sci.sh")
(use "Main")
(use "Scaler")
(use "Osc")
(use "PolyPath")
(use "Polygon")
(use "CueObj")
(use "n958")
(use "Cycle")
(use "Sounds")
(use "View")
(use "Obj")
(script 1000)


(local
    local0 = 1
    local1
    local2

)
(instance public rm1000 of Rm
    (properties
        noun 8
        picture 120
        style 32778
    )

    (method (init)
        proc958_0(128 664 663 673 661 678 660)
        proc0_6(0)
        (switch (gGModNum)
            (case 1005
                (proc0_6(664 2) (send gEgo:
                    posn(160 97)
                    init()
                    setCycle(Walk)
                    setScale(myScaler)
                )
  )
            )
            (case 1010
                ((doorLeft:x(6)) (doorRight:x(20)) (send gRoom:setScript(sEnterFromHall))  )
            )
            (case 1040
                ((send gRoom:setScript(sEnterFromHall))  )
            )
            (default 
                (= local2 1 proc0_10(244 20) (send gEgo:
                    view(663)
                    setLoop(-1)
                    setLoop(0)
                    cel(0)
                    x(120)
                    y(230)
                    setStep(5 4)
                    scaleSignal(1)
                    scaleX(86)
                    scaleY(86)
                    setPri(1)
                    setCycle(0)
                    init()
                )
 (send gRoom:setScript(sUpFromPod)) )
            )
        )
        (light1:
            init()
            setCycle(Fwd)
        )
        (light2:
            init()
            setCycle(Fwd)
        )
        (light3:
            init()
            setCycle(Fwd)
        )
        (light4:
            init()
            setCycle(Fwd)
        )
        (if (proc0_1(59))
            (driveOnOffLight:cel(2))
        )(else
            (driveOnOffLight:cel(0))
        )
        (driveOnOffLight:init())
        (doorLeft:init())
        (doorRight:init())
        (console:init())
        (engine:
            init()
            setOnMeCheck(1 1024)
        )
        (carb:
            init()
            setOnMeCheck(1 64)
        )
        (catwalk:
            init()
            setOnMeCheck(1 8192)
        )
        (guard:
            init()
            hide()
            setScript(sGuardPatrol)
        )
        (send gRoom:addObstacle((send ((Polygon:new())):
                type(3)
                init(36 148 175 148 186 137 319 137 297 96 153 96 156 98 272 98 294 133 176 133 160 144 61 144 43 127 93 127 75 123 42 122 16 100 9 100)
                yourself()
            )
))
        (super:init())
        (send gSq5Music1:
            number(101)
            setLoop(-1)
            play()
        )
        (if (local2)
            (walkCheck:init())
        )
        (send gSQ5:handsOn())
    )


    (method (doit param1)
        Palette(6 65 69 10)
        (if ((< (send gEgo:y) 100) and (== local1 0))
            = local1 1
        )
        (if (proc0_5(gEgo 2) and not (send gRoom:script))
            (send gRoom:setScript(sExitToHall))
        )(else
            (if (proc0_5(gEgo 4) and not (send gRoom:script))
                (send gRoom:setScript(sDownLeftStairs))
            )(else
                (if (proc0_5(gEgo 8) and not (send gRoom:script))
                    (if (< (send gEgo:y) 139)
                        (send gRoom:setScript(sUpDownLittleStairs 0 0))
                    )(else
                        (send gRoom:setScript(sUpDownLittleStairs 0 1))
                    )
                )(else
                    (if (proc999_4(277 100 319 132 gEgo) and not (send gRoom:script))
                        (if (< (send gEgo:y) 110)
                            (send gRoom:setScript(sUpDownRightStairs 0 0))
                        )(else
                            (send gRoom:setScript(sUpDownRightStairs 0 1))
                        )
                    )(else
                        (if ((proc999_4(15 135 90 142 gEgo) and not (send gEgo:scaler)) and not (send gRoom:script))
                            (send gEgo:setScale(Scaler 100 22 145 103))
                        )(else
                            (if (proc999_4(15 143 90 150 gEgo) and (send gEgo:scaler))
                                (send gEgo:setScale(0))
                            )
                        )
                    )
                )
            )
        )
        (super:doit(rest param1))
    )

)
(instance sGuardPatrol of Script
    (properties)

    (method (doit param1)
        (super:doit(rest param1))
        (if (((> (guard:y) 104) and proc999_4(16 100 188 148 gEgo)) or ((> (guard:y) 119) and proc999_4(188 133 319 137 gEgo)))
            (guard:
                setMotion(0)
                setCycle(0)
            )
            = next sGuardShoots
            (self:dispose())
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= seconds (* 10 local0)  )
            )
            (case 1
                (
                (if (proc999_4(16 100 30 120 gEgo))
                    --state
                    = cycles 1
                )(else
                    (guard:show())
                    (doorLeft:x(10))
                    (doorRight:x(17))
                    (send gSq5Music2:
                        number(103)
                        setLoop(1)
                        play()
                    )
                    = ticks 20
                )
 )
            )
            (case 2
                ((doorLeft:x(6)) (doorRight:x(20)) = ticks 20  )
            )
            (case 3
                ((guard:
                    setPri(-1)
                    setLoop(-1)
                    setLoop(2)
                    setCycle(Walk)
                    setMotion(MoveTo 19 111 self)
                )
  )
            )
            (case 4
                ((guard:
                    setLoop(0)
                    setCycle(Osc 1 self)
                )
  )
            )
            (case 5
                ((guard:
                    setLoop(-1)
                    setLoop(2)
                    setCycle(Walk)
                    setMotion(MoveTo 26 120 self)
                )
  )
            )
            (case 6
                ((guard:
                    setLoop(0)
                    setCycle(Osc 1 self)
                )
  )
            )
            (case 7
                ((guard:
                    setLoop(-1)
                    setLoop(2)
                    setCycle(Walk)
                    setMotion(MoveTo 33 129 self)
                )
  )
            )
            (case 8
                ((guard:
                    setLoop(1)
                    setCycle(End self)
                )
  )
            )
            (case 9
                ((guard:
                    setLoop(-1)
                    setLoop(3)
                    setCycle(Walk)
                    setMotion(MoveTo 12 102 self)
                )
  )
            )
            (case 10
                ((guard:setPri(1)) (doorLeft:x(10)) (doorRight:x(17)) (send gSq5Music2:
                    number(103)
                    setLoop(1)
                    play()
                )
 = ticks 6  )
            )
            (case 11
                ((doorLeft:x(13)) (doorRight:x(14)) (guard:hide()) = ticks 6  )
            )
            (case 12
                (
                (if (== local0 1)
                    = local0 3
                )(else
                    = local0 1
                )
 = state -1 = cycles 1  )
            )
            (case 13
                ((self:dispose()) )
            )
        )
    )

)
(instance sGuardShoots of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gSQ5:handsOff()) 
                (switch ((guard:loop))
                    (case 0
                        ((guard:setCycle(Beg self))  )
                    )
                    (case 1
                        ((guard:setCycle(Beg self))  )
                    )
                    (case 3
                        ((guard:
                            setLoop(1)
                            setCel((guard:lastCel()))
                            setCycle(Beg self)
                        )
  )
                    )
                    (default 
                        (= cycles 1 )
                    )
                )
  )
            )
            (case 1
                ((guard:view(673)) 
                (if (< (send gEgo:x) 60)
                    (guard:setLoop(2))
                    (pukeShot:
                        x(- (guard:x) (/ (* 10 (guard:scaleX)) 128))
                        y(- (guard:y) (/ (* 43 (guard:scaleY)) 128))
                    )
                )(else
                    (if (< (send gEgo:x) 145)
                        (guard:setLoop(4))
                        (pukeShot:
                            x(+ (guard:x) (/ (* 9 (guard:scaleX)) 128))
                            y(- (guard:y) (/ (* 38 (guard:scaleY)) 128))
                        )
                    )(else
                        (guard:setLoop(0))
                        (pukeShot:
                            x(+ (guard:x) (/ (* 16 (guard:scaleX)) 128))
                            y(- (guard:y) (/ (* 40 (guard:scaleY)) 128))
                        )
                    )
                )
 (guard:
                    cel(0)
                    setCycle(End)
                )
 (send gSq5Music2:
                    number(519)
                    setLoop(1)
                    play()
                )
 (pukeShot:
                    init()
                    setLoop(-1)
                    setLoop(8)
                    setCel(0)
                    setCycle(0)
                    setStep(20 10)
                    setMotion(MoveTo - (send gEgo:x) (/ (* 5 (send gEgo:scaleX)) 128) - (send gEgo:y) (/ (* 29 (send gEgo:scaleY)) 128) self)
                )
  )
            )
            (case 2
                ((pukeShot:
                    setLoop(9)
                    setCycle(End)
                )
 (send gEgo:
                    view(6501)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 3
                (proc0_9(33) (self:dispose()) )
            )
        )
    )

)
(instance sDownLeftStairs of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gSQ5:handsOff()) (send gEgo:
                    view(663)
                    setLoop(-1)
                    setLoop(1)
                    cel(0)
                    setStep(5 4)
                    setScale(0)
                    scaleX(86)
                    scaleY(86)
                    scaleSignal(1)
                    setPri(1)
                    setCycle(Walk)
                    setMotion(MoveTo 120 230 self)
                )
  )
            )
            (case 1
                ((send gTestMessager:say(6 3 0 0 self))  )
            )
            (case 2
                ((send gEgo:
                    setLoop(0)
                    setMotion(MoveTo 116 188 self)
                )
  )
            )
            (case 3
                ((walkCheck:init()) (send gSQ5:handsOn()) (self:dispose()) )
            )
        )
    )

)
(instance sUpFromPod of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gSQ5:handsOff()) = seconds 2  )
            )
            (case 1
                ((send gEgo:
                    setLoop(0)
                    setMotion(MoveTo 116 188 self)
                )
  )
            )
            (case 2
                ((walkCheck:init()) (send gSQ5:handsOn()) (self:dispose()) )
            )
        )
    )

)
(instance sEnterFromHall of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gSQ5:handsOff()) (send gEgo:
                    view(664)
                    x(13)
                    y(102)
                    setScale(Scaler 100 22 145 103)
                    setCycle(Walk)
                    init()
                    setMotion(MoveTo 14 110 self)
                )
  )
            )
            (case 1
                ((doorLeft:x(10)) (doorRight:x(17)) (send gSq5Music2:
                    number(103)
                    setLoop(1)
                    play()
                )
 = ticks 20  )
            )
            (case 2
                ((doorLeft:x(13)) (doorRight:x(14)) (walkCheck:dispose()) = ticks 20  )
            )
            (case 3
                ((send gSQ5:handsOn()) (self:dispose()) )
            )
        )
    )

)
(instance sExitToHall of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gSQ5:handsOff()) (doorLeft:x(10)) (doorRight:x(17)) (send gSq5Music2:
                    number(103)
                    setLoop(1)
                    play()
                )
 = ticks 20  )
            )
            (case 1
                ((doorLeft:x(6)) (doorRight:x(20)) = ticks 20  )
            )
            (case 2
                ((send gEgo:setMotion(MoveTo 13 102 self))  )
            )
            (case 3
                ((send gRoom:newRoom(1010)) (self:dispose()) )
            )
        )
    )

)
(instance sUpLeftStairs of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gSQ5:handsOff()) (send gEgo:
                    setLoop(-1)
                    setLoop(0)
                    cel(0)
                    setCycle(Walk)
                    setMotion(MoveTo 73 125 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    view(664)
                    cel(0)
                    setLoop(-1)
                    loop(1)
                    setPri(-1)
                    setScale(Scaler 100 22 145 103)
                    setCycle(Walk)
                    setMotion(MoveTo - (send gEgo:x) 5 (send gEgo:y) self)
                )
  )
            )
            (case 2
                ((walkCheck:dispose()) (send gSQ5:handsOn()) (self:dispose()) )
            )
        )
    )

)
(instance sUpDownRightStairs of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gSQ5:handsOff()) 
                (if (register)
                    (send gEgo:
                        view(663)
                        cel(0)
                        setLoop(-1)
                        setLoop(0)
                        setStep(5 4)
                        cycleSpeed(4)
                        y(132)
                        setCycle(Walk)
                        setMotion(PolyPath - (send gEgo:x) 23 98 self)
                    )
                )(else
                    (send gEgo:
                        view(663)
                        cel(0)
                        setLoop(-1)
                        setLoop(1)
                        setScale(0)
                        setCycle(Walk)
                        setMotion(PolyPath + (send gEgo:x) 21 136 self)
                    )
                )
 )
            )
            (case 1
                (
                (if (register)
                    (send gEgo:
                        view(664)
                        cel(0)
                        setLoop(-1)
                        loop(1)
                        cycleSpeed(6)
                        setCycle(Walk)
                        setScale(myScaler)
                        setMotion(PolyPath 237 98 self)
                    )
                )(else
                    (send gEgo:
                        view(664)
                        cel(0)
                        setLoop(-1)
                        loop(1)
                        setCycle(Walk)
                        setMotion(PolyPath 280 136 self)
                    )
                )
 )
            )
            (case 2
                ((send gSQ5:handsOn()) (self:dispose()) )
            )
        )
    )

)
(instance sUpDownLittleStairs of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gSQ5:handsOff()) 
                (if (not register)
                    (send gEgo:setMotion(PolyPath (- (send gEgo:x) 15) (send gEgo:y) self))
                )(else
                    = cycles 1
                )
 )
            )
            (case 1
                (
                (if (register)
                    (send gEgo:
                        view(664)
                        setLoop(-1)
                        setLoop(8)
                        cel(0)
                        x(168)
                        y(139)
                        setCycle(End self)
                    )
                )(else
                    (send gEgo:
                        view(664)
                        setLoop(-1)
                        setLoop(9)
                        cel(0)
                        x(170)
                        y(135)
                        setCycle(End self)
                    )
                )
 )
            )
            (case 2
                ((send gEgo:
                    view(664)
                    cel(0)
                    setLoop(-1)
                    setCycle(Walk)
                )
 
                (if (register)
                    (send gEgo:
                        loop(0)
                        cel(6)
                        x(190)
                        y(136)
                        setMotion(MoveTo 208 136 self)
                    )
                )(else
                    (send gEgo:
                        loop(1)
                        cel(1)
                        x(155)
                        y(145)
                        setMotion(MoveTo 130 145 self)
                    )
                )
 )
            )
            (case 3
                ((send gSQ5:handsOn()) (self:dispose()) )
            )
        )
    )

)
(instance guard of Actor
    (properties
        x 12
        y 102
        noun 7
        view 661
        loop 2
        priority 1
        signal 16400
        cycleSpeed rm1000
        moveSpeed rm1000
    )

    (method (init param1)
        (super:init(rest param1))
        (self:setScale(Scaler 100 22 145 103))
    )

)
(instance pukeShot of Actor
    (properties
        view 678
        signal 16384
        moveSpeed 0
    )

    (method (init param1)
        (super:init(rest param1))
        (self:setScale(Scaler 100 22 145 103))
    )

)
(instance light1 of Prop
    (properties
        x 141
        y 81
        noun 8
        view 660
        signal 16384
        cycleSpeed rm1000
    )
)
(instance light2 of Prop
    (properties
        x 143
        y 77
        noun 8
        view 660
        loop 1
        signal 16384
    )
)
(instance light3 of Prop
    (properties
        x 155
        y 80
        noun 8
        view 660
        loop 2
        signal 16384
        cycleSpeed 14
    )
)
(instance light4 of Prop
    (properties
        x 156
        y 83
        noun 8
        view 660
        loop 2
        signal 16384
        cycleSpeed rm1000
    )
)
(instance driveOnOffLight of Prop
    (properties
        x 165
        y 78
        noun 8
        view 660
        loop 3
        signal 16384
    )
)
(instance doorLeft of View
    (properties
        x 13
        y 93
        noun 3
        view 660
        loop 4
        priority 2
        signal 16400
    )
)
(instance doorRight of View
    (properties
        x 14
        y 93
        noun 3
        view 660
        loop 4
        cel 1
        priority 2
        signal 16400
    )
)
(instance catwalk of Feature
    (properties
        x 150
        y 84
        noun 2
        onMeCheck 8192
    )
)
(instance carb of Feature
    (properties
        x 150
        y 84
        noun 1
        onMeCheck 64
    )
)
(instance engine of Feature
    (properties
        x 150
        y 84
        noun 4
        onMeCheck 1024
    )
)
(instance console of Feature
    (properties
        x 150
        y 84
        noun 5
        nsTop 74
        nsLeft 120
        nsBottom 97
        nsRight 184
    )

    (method (doVerb param1 param2)
        (switch (param1)
            (case 4
                (
                (if (proc999_4(153 92 174 100 gEgo))
                    (send gRoom:newRoom(1005))
                )(else
                    (send gTestMessager:say(5 4 1 0))
                )
 )
            )
            (default 
                ((super:doVerb(param1 rest param2)) )
            )
        )
    )

)
(instance walkCheck of Feature
    (properties
        x 150
        y 84
        nsBottom 189
        nsRight 319
    )

    (method (init param1)
        (super:init(rest param1))
        (send gWalkHandler:addToFront(walkCheck))
    )


    (method (dispose param1)
        (send gWalkHandler:delete(walkCheck))
        (super:dispose(rest param1))
    )


    (method (doVerb param1 param2)
        (switch (param1)
            (case 3
                ((send gRoom:setScript(sUpLeftStairs))  )
            )
            (default 
                ((super:doVerb(param1 rest param2)) )
            )
        )
    )

)
(instance myScaler of Scaler
    (properties)

    (method (init theClient)
        (if (paramTotal)
            = client theClient
        )
        (self:doit())
    )


    (method (doit)
        (if (> (send gEgo:x) 250)
            (send gEgo:
                scaleSignal(1)
                scaleX(128)
                scaleY(128)
            )
        )(else
            (send gEgo:
                scaleSignal(1)
                scaleX(- 128 (/ (* 2 (- 250 (send gEgo:x))) 3))
                scaleY((send gEgo:scaleX))
            )
        )
    )

)
