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


(local
    local0[4] = (123 131 99 123 )
    local10[4] = (114 116 155 162 )
    local8
    local9
    local10

)
(procedure (localproc_0052)
    = global144 (= global143 Random(0 3))
    (doortop:setCel((doortop:lastCel())))
    (send gRoom:setScript(sExitSubfloor 0 0))
)


(procedure (localproc_0080)
    = global144 (= global143 (* 2 Random(0 1)))
    (doorbtm:setCel((doorbtm:lastCel())))
    (send gRoom:setScript(sExitSubfloor 0 1))
)


(instance public rm1035 of Rm
    (properties
        noun 5
        picture 125
        style 32778
    )

    (method (init)
        proc958_0(128 670)
        (send gEgo:y(189))
        (switch (global133)
            (case 1
                (= local8 1 = local9 2  )
            )
            (case 2
                (= local8 1 = local9 2  )
            )
            (case 3
                (= local8 1 = local9 2  )
            )
            (case 4
                (
                (if (== global134 3)
                    = local8 1
                    = local9 2
                )(else
                    = local8 4
                    = local9 5
                )
 )
            )
            (case 5
                (= local8 4 = local9 5  )
            )
            (case 6
                (
                (if (== global134 2)
                    = local8 4
                    = local9 5
                )(else
                    = local8 6
                    = local9 7
                )
 )
            )
            (case 7
                (
                (if (== global134 3)
                    = local8 0
                    = local9 0
                )(else
                    (if (== global134 2)
                        = local8 4
                        = local9 5
                    )(else
                        = local8 6
                        = local9 7
                    )
                )
 )
            )
            (case 8
                (
                (if (== global134 3)
                    = local8 0
                    = local9 0
                )(else
                    = local8 6
                    = local9 7
                )
 )
            )
            (case 9
                (= local8 6 = local9 7 )
            )
        )
        (switch (gGModNum)
            (case 1020
                (
                (if (((== global133 1) or (== global133 4)) or (== global133 6))
                    localproc_0052()
                )(else
                    localproc_0080()
                )
 )
            )
            (default 
                ((send gEgo:
                    view(670)
                    setLoop(-1)
                    setLoop(1)
                    cel(0)
                    x(94)
                    y(165)
                    init()
                    setScale(Scaler 111 26 158 96)
                    setCycle(Walk)
                )
 )
            )
        )
        (doortop:init())
        (doorbtm:init())
        (turbtop:init())
        (turboDoors:
            init()
            setOnMeCheck(1 16384)
        )
        (ladder:
            init()
            setOnMeCheck(1 64)
        )
        (switch (global143)
            (case 3
                ((liftBtm:
                    scaleX(90)
                    scaleY(90)
                    init()
                    setScript(sLift)
                )
  )
            )
            (case 2
                ((liftBtm:
                    scaleX(160)
                    scaleY(160)
                    init()
                    setScript(sLift)
                )
  )
            )
            (default 
                ((liftBtm:
                    scaleX(320)
                    scaleY(320)
                    init()
                    hide()
                    setScript(sLift)
                )
 )
            )
        )
        (send gRoom:addObstacle((send ((Polygon:new())):
                type(3)
                init(88 180 133 100 129 102 86 173)
                yourself()
            )
))
        (super:init())
        (send gDirectionHandler:addToFront(doorbtm))
    )


    (method (doit param1)
        (super:doit(rest param1))
        Palette(6 78 82 1 231 235 1)
        (if ((<> global144 global143) and (== local10 0))
            (theMusic3:
                number(128)
                setLoop(-1)
                play()
            )
            = local10 1
        )(else
            (if ((== global144 global143) and (== local10 1))
                (theMusic3:stop())
                = local10 0
            )
        )
        (if (((> (send gEgo:y) 166) and not (send gRoom:script)) and not (send gEgo:script))
            (send gRoom:newRoom(1030))
        )
    )


    (method (dispose param1)
        (theMusic3:dispose())
        (send gDirectionHandler:delete(doorbtm))
        (if (<> global144 global143)
            = global144 3
            = global143 3
        )
        (super:dispose(rest param1))
    )

)
(instance sEnterSubfloor of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gSQ5:handsOff()) (send gEgo:setMotion(PolyPath local0[(* register 2)] local10[(* register 2)] self))  )
            )
            (case 1
                ((send gEgo:
                    setLoop(3)
                    cel(0)
                    x(local0[+ (* register 2) 1])
                    y(local10[+ (* register 2) 1])
                    setCycle(CT 3 1 self)
                )
  )
            )
            (case 2
                (
                (if (== register 0)
                    (doortop:setCycle(End self))
                )(else
                    (doorbtm:setCycle(End self))
                )
 (send gSq5Music2:
                    number(103)
                    setLoop(1)
                    play()
                )
  )
            )
            (case 3
                ((send gEgo:setCycle(End self))  )
            )
            (case 4
                (
                (if (== register 0)
                    = global133 local8
                )(else
                    = global133 local9
                )
 (send gRoom:newRoom(1020)) (self:dispose()) )
            )
        )
    )

)
(instance sExitSubfloor of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gSQ5:handsOff()) (send gEgo:
                    view(670)
                    setLoop(-1)
                    setLoop(3)
                    setCel((send gEgo:lastCel()))
                    setScale(Scaler 111 26 158 96)
                    x(local0[+ (* register 2) 1])
                    y(local10[+ (* register 2) 1])
                    init()
                    setCycle(CT 3 -1 self)
                )
  )
            )
            (case 1
                (
                (if (== register 0)
                    (doortop:setCycle(Beg self))
                )(else
                    (doorbtm:setCycle(Beg self))
                )
 (send gSq5Music2:
                    number(103)
                    setLoop(1)
                    play()
                )
 (send gEgo:setCycle(Beg self))  )
            )
            (case 2
                ((send gEgo:
                    view(670)
                    setLoop(-1)
                    setLoop(1)
                    setCycle(Walk)
                    x(local0[* register 2])
                    y(local10[* register 2])
                    cel(0)
                )
 (send gSQ5:handsOn()) (self:dispose()) )
            )
        )
    )

)
(instance sLift of Script
    (properties)

    (method (doit param1)
        (if ((> (liftBtm:nsBottom) (- (send gEgo:y) 5)) and not (send gEgo:script))
            (if (== global144 global143)
                = global144 0
                = seconds 0
                = state 1
                (self:cue())
            )
            (send gEgo:setScript(sSquishRog))
        )
        (super:doit(rest param1))
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (
                (if ((send gEgo:script))
                    (self:dispose())
                )(else
                    = seconds 15
                )
 )
            )
            (case 1
                (
                (switch (global143)
                    (case 3
                        (= global144 Random(0 2)  )
                    )
                    (case 2
                        (
                        (if (Random(0 1))
                            = state 8
                            = global144 3
                        )(else
                            = state 3
                            = global144 Random(0 1)
                        )
 )
                    )
                    (default 
                        (= state 5 = global144 Random(2 3) )
                    )
                )
 = ticks 1  )
            )
            (case 2
                (
                (if (< (liftBtm:scaleX) 160)
                    (liftBtm:scaleX((+ (liftBtm:scaleX) 10)))
                    (liftBtm:scaleY((+ (liftBtm:scaleY) 10)))
                    --state
                )
 = ticks 10  )
            )
            (case 3
                (
                (if (== (= global143 2) global144)
                    = state -1
                )
 = cycles 1  )
            )
            (case 4
                (
                (if (< (liftBtm:scaleX) 320)
                    (liftBtm:scaleX((+ (liftBtm:scaleX) 10)))
                    (liftBtm:scaleY((+ (liftBtm:scaleY) 10)))
                    --state
                )
 = ticks 10  )
            )
            (case 5
                (= global143 global144 (liftBtm:hide()) = state -1 = cycles 1  )
            )
            (case 6
                ((liftBtm:
                    show()
                    scaleX(320)
                    scaleY(320)
                )
 = cycles 1  )
            )
            (case 7
                (
                (if (> (liftBtm:scaleX) 160)
                    (liftBtm:scaleX((- (liftBtm:scaleX) 10)))
                    (liftBtm:scaleY((- (liftBtm:scaleY) 10)))
                    --state
                )
 = ticks 10  )
            )
            (case 8
                (
                (if (== (= global143 2) global144)
                    = state -1
                )
 = cycles 1  )
            )
            (case 9
                (
                (if (> (liftBtm:scaleX) 90)
                    (liftBtm:scaleX((- (liftBtm:scaleX) 10)))
                    (liftBtm:scaleY((- (liftBtm:scaleY) 10)))
                    --state
                )
 = ticks 10  )
            )
            (case 10
                (= global143 3 = state -1 = cycles 1  )
            )
            (case 11
                ((self:dispose()) )
            )
        )
    )

)
(instance sSquishRog of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gSQ5:handsOff()) 
                (if (> global143 global144)
                    = global144 0
                )(else
                    = global144 3
                    = state 1
                )
 = cycles 1  )
            )
            (case 1
                (
                (if (< (liftBtm:nsBottom) (send gEgo:y))
                    --state
                )
 = cycles 1  )
            )
            (case 2
                ((send gEgo:
                    view(671)
                    setLoop(-1)
                    setLoop(1)
                    cel(0)
                    setCycle(0)
                )
 = ticks 1  )
            )
            (case 3
                (
                (if ((liftBtm:script))
                    --state
                )
 = cycles 1  )
            )
            (case 4
                ((send gEgo:setCycle(End self))  )
            )
            (case 5
                (proc0_9(34) (self:dispose()) )
            )
        )
    )

)
(instance liftBtm of Actor
    (properties
        x 138
        y 72
        noun 6
        view 670
        loop 6
        scaleSignal 1
        scaleX 90
        scaleY 90
    )

    (method (doit param1)
        (super:doit(rest param1))
        (if ((send gEgo:script))
            (self:setPri(14))
        )(else
            (self:setPri(CoordPri(nsBottom)))
        )
    )

)
(instance doortop of Actor
    (properties
        x 154
        y 106
        noun 7
        view 670
        loop 10
        priority 1
        signal 16400
    )

    (method (doVerb param1 param2)
        (switch (param1)
            (case 4
                (
                (if (not (send gEgo:script))
                    (send gRoom:setScript(sEnterSubfloor 0 0))
                )
 )
            )
            (default 
                ((super:doVerb(param1 rest param2)) )
            )
        )
    )

)
(instance doorbtm of Actor
    (properties
        x 161
        y 134
        noun 7
        view 670
        loop 8
        priority 1
        signal 16400
    )

    (method (handleEvent pEvent param2)
        return 
            (if (((send gUser:canControl()) and (& (send pEvent:type) $0040)) and (== (send gSq5IconBar:curIcon) (send gSq5IconBar:at(0))))
                (switch ((send pEvent:message))
                    (case 0
                        (send gEgo:setMotion(0))
                    )
                    (case 1
                        (if ((send gEgo:mover))
                            (send gEgo:setMotion(0))
                        )(else
                            (send gEgo:setMotion(PolyPath 129 100))
                        )
                    )
                    (case 2
                        (if ((send gEgo:mover))
                            (send gEgo:setMotion(0))
                        )(else
                            (send gEgo:setMotion(PolyPath 129 100))
                        )
                    )
                    (case 4
                        (if ((send gEgo:mover))
                            (send gEgo:setMotion(0))
                        )(else
                            (send gEgo:setMotion(PolyPath 94 167))
                        )
                    )
                    (case 5
                        (if ((send gEgo:mover))
                            (send gEgo:setMotion(0))
                        )(else
                            (send gEgo:setMotion(PolyPath 94 167))
                        )
                    )
                    (case 6
                        (if ((send gEgo:mover))
                            (send gEgo:setMotion(0))
                        )(else
                            (send gEgo:setMotion(PolyPath 94 167))
                        )
                    )
                    (case 8
                        (if ((send gEgo:mover))
                            (send gEgo:setMotion(0))
                        )(else
                            (send gEgo:setMotion(PolyPath 129 100))
                        )
                    )
                )
                (send pEvent:claimed(1))
                return 1
            )(else
                (super:handleEvent(pEvent rest param2))
            )
    )


    (method (doVerb param1 param2)
        (switch (param1)
            (case 4
                (
                (if (not (send gEgo:script))
                    (send gRoom:setScript(sEnterSubfloor 0 1))
                )
 )
            )
            (default 
                ((super:doVerb(param1 rest param2)) )
            )
        )
    )

)
(instance turbtop of View
    (properties
        x 143
        y 80
        view 670
        loop 11
    )
)
(instance turboDoors of Feature
    (properties
        x 160
        y 120
        noun 3
        onMeCheck 16384
    )
)
(instance ladder of Feature
    (properties
        x 220
        y sExitSubfloor
        noun 4
        onMeCheck 64
    )
)
(instance theMusic3 of Sound
    (properties
        flags 1
    )
)
