(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 1030)


(local
    local0[2] = (210 192 )
    local4[2] = (141 108 )
    local6
    local5
    local6

)
(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 rm1030 of Rm
    (properties
        noun 5
        picture 124
        style 32778
        vanishingX 179
        vanishingY 83
    )

    (method (init)
        proc958_0(128 670)
        (send gEgo:y(189))
        (switch (global133)
            (case 1
                (= local6 3 = local5 4  )
            )
            (case 2
                (= local6 3 = local5 4  )
            )
            (case 3
                (= local6 3 = local5 4  )
            )
            (case 4
                (
                (if (== global134 3)
                    = local6 3
                    = local5 4
                )(else
                    = local6 6
                    = local5 7
                )
 )
            )
            (case 5
                (= local6 6 = local5 7  )
            )
            (case 6
                (
                (if (== global134 2)
                    = local6 6
                    = local5 7
                )(else
                    = local6 8
                    = local5 9
                )
 )
            )
            (case 7
                (
                (if (== global134 3)
                    = local6 7
                    = local5 8
                )(else
                    (if (== global134 2)
                        = local6 6
                        = local5 7
                    )(else
                        = local6 8
                        = local5 9
                    )
                )
 )
            )
            (case 8
                (
                (if (== global134 3)
                    = local6 7
                    = local5 8
                )(else
                    = local6 8
                    = local5 9
                )
 )
            )
            (case 9
                (= local6 8 = local5 9 )
            )
        )
        (switch (gGModNum)
            (case 1020
                (
                (switch (global133)
                    (case 3
                        (localproc_0052()  )
                    )
                    (case 4
                        (localproc_0080()  )
                    )
                    (case 6
                        (localproc_0052()  )
                    )
                    (case 7
                        (
                        (if (== global134 3)
                            localproc_0052()
                        )(else
                            localproc_0080()
                        )
 )
                    )
                    (case 8
                        (
                        (if (== global134 3)
                            localproc_0080()
                        )(else
                            localproc_0052()
                        )
 )
                    )
                    (case 9
                        (localproc_0080() )
                    )
                )
  )
            )
            (default 
                ((send gEgo:
                    view(670)
                    setLoop(-1)
                    setLoop(0)
                    cel(0)
                    x(218)
                    y(159)
                    init()
                    setScale(Scaler 111 26 158 96)
                    setCycle(Walk)
                )
 )
            )
        )
        (doortop:init())
        (doorbtm:init())
        (turbbtm:init())
        (turboDoors:
            init()
            setOnMeCheck(1 16384)
        )
        (ladder:
            init()
            setOnMeCheck(1 64)
        )
        (switch (global143)
            (case 0
                ((liftTop:
                    scaleX(90)
                    scaleY(90)
                    init()
                    setScript(sLift)
                )
  )
            )
            (case 1
                ((liftTop:
                    scaleX(160)
                    scaleY(160)
                    init()
                    setScript(sLift)
                )
  )
            )
            (default 
                ((liftTop:
                    scaleX(320)
                    scaleY(320)
                    init()
                    hide()
                    setScript(sLift)
                )
 )
            )
        )
        (send gRoom:addObstacle((send ((Polygon:new())):
                type(3)
                init(228 171 179 84 181 91 227 178)
                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 (== local6 0))
            (theMusic3:
                number(128)
                setLoop(-1)
                play()
            )
            = local6 1
        )(else
            (if ((== global144 global143) and (== local6 1))
                (theMusic3:stop())
                = local6 0
            )
        )
        (if (proc0_5(gEgo 8192))
            (send gEgo:
                y(+ (send gEgo:y) 1)
                setMotion(0)
            )
            (send gTestMessager:say(1 0 0 0))
        )(else
            (if (((> (send gEgo:y) 160) and not (send gRoom:script)) and not (send gEgo:script))
                (if ((== global134 3) and (> global133 6))
                    (send gTestMessager:say(2 0 0 0))
                    (send gEgo:
                        setMotion(0)
                        x(215)
                        y(151)
                    )
                )(else
                    (send gRoom:newRoom(1035))
                )
            )
        )
    )


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

)
(instance sEnterSubfloor of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gEgo:setMotion(PolyPath local0[register] local4[(send gSQ5:handsOff())] self))  )
            )
            (case 1
                ((send gEgo:
                    setLoop(2)
                    cel(0)
                    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 local6
                )(else
                    = global133 local5
                )
 (send gRoom:newRoom(1020)) (self:dispose()) )
            )
        )
    )

)
(instance sExitSubfloor of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gSQ5:handsOff()) = seconds 3  )
            )
            (case 1
                ((send gEgo:
                    view(670)
                    setLoop(-1)
                    setLoop(2)
                    setCel((send gEgo:lastCel()))
                    x(local0[register])
                    y(local4[register])
                    setScale(Scaler 111 26 158 96)
                    init()
                    setCycle(CT 3 -1 self)
                )
  )
            )
            (case 2
                (
                (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 3
                ((send gSQ5:handsOn()) (send gEgo:
                    view(670)
                    setLoop(-1)
                    setLoop(0)
                    setCycle(Walk)
                    cel(0)
                )
 (self:dispose()) )
            )
        )
    )

)
(instance sLift of Script
    (properties)

    (method (doit param1)
        (if ((> (liftTop:nsBottom) (- (send gEgo:y) (/ (send gEgo:scaleX) 18))) and not (send gEgo:script))
            (if (== global144 global143)
                = global144 3
                = 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 0
                        (= global144 Random(1 3)  )
                    )
                    (case 1
                        (
                        (if (Random(0 1))
                            = state 8
                            = global144 0
                        )(else
                            = global144 Random(2 (= state 3))
                        )
 )
                    )
                    (default 
                        (= state 5 = global144 Random(0 1) )
                    )
                )
 = ticks 1  )
            )
            (case 2
                (
                (if (< (liftTop:scaleX) 160)
                    (liftTop:scaleX((+ (liftTop:scaleX) 10)))
                    (liftTop:scaleY((+ (liftTop:scaleY) 10)))
                    --state
                )
 = ticks 10  )
            )
            (case 3
                (
                (if (== (= global143 1) global144)
                    = state -1
                )
 = cycles 1  )
            )
            (case 4
                (
                (if (< (liftTop:scaleX) 320)
                    (liftTop:scaleX((+ (liftTop:scaleX) 10)))
                    (liftTop:scaleY((+ (liftTop:scaleY) 10)))
                    --state
                )
 = ticks 10  )
            )
            (case 5
                (= global143 global144 (liftTop:hide()) = state -1 = cycles 1  )
            )
            (case 6
                ((liftTop:
                    show()
                    scaleX(320)
                    scaleY(320)
                )
 = cycles 1  )
            )
            (case 7
                (
                (if (> (liftTop:scaleX) 160)
                    (liftTop:scaleX((- (liftTop:scaleX) 10)))
                    (liftTop:scaleY((- (liftTop:scaleY) 10)))
                    --state
                )
 = ticks 10  )
            )
            (case 8
                (
                (if (== (= global143 1) global144)
                    = state -1
                )
 = cycles 1  )
            )
            (case 9
                (
                (if (> (liftTop:scaleX) 90)
                    (liftTop:scaleX((- (liftTop:scaleX) 10)))
                    (liftTop:scaleY((- (liftTop:scaleY) 10)))
                    --state
                )
 = ticks 10  )
            )
            (case 10
                (= global143 0 = 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 (< (liftTop:nsBottom) (send gEgo:y))
                    --state
                )
 = cycles 1  )
            )
            (case 2
                ((send gEgo:
                    view(671)
                    setLoop(-1)
                    setLoop(0)
                    cel(0)
                    setCycle(0)
                )
 = ticks 1  )
            )
            (case 3
                (
                (if ((liftTop:script))
                    --state
                )
 = cycles 1  )
            )
            (case 4
                ((send gEgo:setCycle(End self))  )
            )
            (case 5
                (proc0_9(34) (self:dispose()) )
            )
        )
    )

)
(instance liftTop of Actor
    (properties
        x 167
        y 70
        noun 6
        view 670
        loop 5
        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 157
        y 134
        noun 7
        view 670
        loop 7
        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 165
        y 106
        noun 7
        view 670
        loop 9
        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 186 98))
                        )
                    )
                    (case 2
                        (if ((send gEgo:mover))
                            (send gEgo:setMotion(0))
                        )(else
                            (send gEgo:setMotion(PolyPath 186 98))
                        )
                    )
                    (case 4
                        (if ((send gEgo:mover))
                            (send gEgo:setMotion(0))
                        )(else
                            (send gEgo:setMotion(PolyPath 221 161))
                        )
                    )
                    (case 5
                        (if ((send gEgo:mover))
                            (send gEgo:setMotion(0))
                        )(else
                            (send gEgo:setMotion(PolyPath 221 161))
                        )
                    )
                    (case 6
                        (if ((send gEgo:mover))
                            (send gEgo:setMotion(0))
                        )(else
                            (send gEgo:setMotion(PolyPath 221 161))
                        )
                    )
                    (case 8
                        (if ((send gEgo:mover))
                            (send gEgo:setMotion(0))
                        )(else
                            (send gEgo:setMotion(PolyPath 186 98))
                        )
                    )
                )
                (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 turbbtm of View
    (properties
        x 176
        y 81
        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 130
        noun 4
        onMeCheck 64
    )
)
(instance theMusic3 of Sound
    (properties
        flags 1
    )
)
