(include "sci.sh")
(use "Main")
(use "sewer")
(use "MoveToY")
(use "SQRoom")
(use "PolyPath")
(use "Polygon")
(use "Cycle")
(use "Obj")
(script 105)


(local
    local0

)
(instance public rm105 of SQRoom
    (properties
        picture 105
        horizon 50
        east 110
        picAngle 70
        vanishingX 319
        vanishingY 65446
    )

    (method (init)
        (sewer:roomVer(22691))
        Load(rsVIEW 80)
        (switch (gWest)
            (case 110
                (if ((== (sewer:location) 115) or (== (sewer:status) 2))
                    (sewer:
                        status(0)
                        location(0)
                    )
                )
                (if ((== (sewer:status) 8) and (== (sewer:location) 105))
                    (send (ScriptID(702 2)):
                        init()
                        hide()
                        posn(181 32)
                        setLoop(0)
                        setCycle(Fwd)
                        setScript(slimeLeavingUp)
                    )
                )
                (self:
                    setScript(enterRight)
                    style(40)
                )
            )
            (case 90
                (if ((== (sewer:location) 105) and (== (sewer:status) 6))
                    (if (not Random(0 2))
                        (sewer:status(3))
                    )(else
                        (send (ScriptID(702 2)):
                            posn(Random(286 334) 125)
                            init()
                            setCycle(Fwd)
                            setScript(slimeLeavingR)
                        )
                    )
                )
                (self:
                    setScript(enterNorth)
                    style(30)
                )
            )
            (default 
                (send gLongSong:
                    number(805)
                    vol(127)
                    loop(-1)
                    playBed()
                )
                (self:
                    setScript(enterNorth)
                    style(30)
                )
            )
        )
        (send (ScriptID(702 5)):
            init()
            setLoop(12)
            posn(233 114)
            setPri(5)
            cycleSpeed(1)
            setCycle(Fwd)
        )
        (super:init())
        (send gEgo:init())
        (send (ScriptID(702 2)):show())
        (self:
            setRegions(702)
            addObstacle((send ((Polygon:new())):
                    type(2)
                    init(225 0 85 111 78 124 77 132 83 135 319 135 319 189 0 189 0 0)
                    yourself()
                )
 (send ((Polygon:new())):
                    type(2)
                    init(319 0 319 132 101 132 94 124 99 115 237 0)
                    yourself()
                )
)
        )
        (if (((== (sewer:location) 0) and (== (sewer:status) 0)) and (<> gWest 110))
            (sewer:status(1))
        )
    )


    (method (doit)
        (if (script)
            0
        )(else
            (if (== (send gEgo:edgeHit) 1)
                proc0_2()
                (self:setScript(exitScript))
            )(else
                (if (== (send gEgo:edgeHit) 2)
                    (if ((< (send (ScriptID(702 2)):y) 85) and (== (sewer:location) 105))
                        (sewer:status(8))
                    )
                    (if (== (send (ScriptID(702 2)):loop) 0)
                        (send gLongSong:
                            vol(127)
                            playBed()
                        )
                        (send gLongSong2:
                            vol(0)
                            fade(0 10 10 0)
                        )
                    )
                )(else
                    (if (((== (sewer:status) 3) and (<> (sewer:location) 105)) and (> (sewer:rmTimer) 11))
                        (sewer:
                            location(0)
                            status(0)
                        )
                    )
                )
            )
        )
        (super:doit())
        (if (((< (send gEgo:y) 171) and (> (send gEgo:y) 126)) and (== (sewer:status) 1))
            (sewer:status(2))
            (send (ScriptID(702 3)):
                init()
                hide()
                setScript(dripScript)
            )
        )
        (if ((((== (sewer:status) 3) and (== (sewer:location) 110)) and (< (send gEgo:x) 245)) and (< (sewer:rmTimer) 12))
            (sewer:location(105))
            (send (ScriptID(702 2)):
                init()
                show()
                setLoop(2)
                moveSpeed(0)
                posn(347 125)
                setCycle(Fwd)
                cycleSpeed(0)
                setScript(ScriptID(702 4))
            )
        )
        (if (((== (sewer:status) 6) and (== (sewer:location) 90)) and (> (sewer:rmTimer) 8))
            (sewer:
                location(0)
                status(0)
            )
        )
        (if (((< (send gEgo:x) 128) and (== (sewer:location) 110)) and (== (sewer:status) 3))
            (sewer:
                status(0)
                location(0)
            )
        )
        (if (< (send gEgo:y) 58)
            (send gEgo:setPri(4))
        )(else
            (send gEgo:setPri(-1))
        )
    )

)
(instance exitScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    setPri(4)
                    setLoop(-1)
                    setHeading(46)
                    setMotion(MoveToY 65530 self)
                )
            )
            (case 1
                (if (== (sewer:location) 110)
                    (sewer:
                        status(0)
                        location(0)
                    )
                )
                (send global2:newRoom(90))
            )
        )
    )

)
(instance dripScript of Script
    (properties)

    (method (changeState newState)
        (var temp0[2])
        (switch (= state newState)
            (case 0
                = seconds Random(2 8)
            )
            (case 1
                (if ((> (send gEgo:x) 265) or (< (send gEgo:y) 110))
                    (self:init())
                )(else
                    (self:cue())
                )
            )
            (case 2
                (send gLongSong:
                    vol(0)
                    fade(0 10 10 0)
                )
                (send gLongSong2:
                    vol(127)
                    number(806)
                    loop(1)
                    play()
                )
                (send (ScriptID(702 3)):
                    show()
                    setLoop(5)
                    posn(139 11)
                    cel(0)
                    cycleSpeed(1)
                    setCycle(CT 9 1 self)
                )
            )
            (case 3
                (send (ScriptID(702 3)):setCycle(End))
                (send (ScriptID(702 2)):
                    init()
                    show()
                    setLoop(7)
                    cycleSpeed(1)
                    setCycle(End self)
                    posn(167 41)
                )
            )
            (case 4
                (send gLongSong2:
                    vol(127)
                    number(819)
                    loop(-1)
                    play()
                )
                (sewer:
                    location(105)
                    status(3)
                )
                (send (ScriptID(702 2)):
                    setLoop(0)
                    setCycle(Fwd)
                    cycleSpeed(0)
                    setScript(ScriptID(702 4))
                    moveSpeed(1)
                )
                (self:dispose())
            )
        )
    )

)
(instance enterRight of Script
    (properties)

    (method (changeState newState)
        (var temp0[2])
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    posn(309 134)
                    setMotion(MoveTo 297 135 self)
                )
                (if ((== (sewer:status) 3) and (== (sewer:location) 105))
                    (if (> (sewer:oldDistance) 160)
                        (sewer:oldDistance(160))
                    )
                    (send (ScriptID(702 2)):
                        init()
                        hide()
                        posn(- 320 (sewer:oldDistance) 125)
                        moveSpeed(0)
                        setLoop(2)
                        setScript(ScriptID(702 4))
                    )
                    (send gLongSong:
                        vol(0)
                        fade(0 10 10 0)
                    )
                    (send gLongSong2:
                        vol(127)
                        number(819)
                        loop(-1)
                        play()
                    )
                )
                (if ((== (sewer:status) 6) and (== (sewer:location) 105))
                    (send (ScriptID(702 2)):
                        init()
                        hide()
                        posn(359 125)
                        setLoop(2)
                        moveSpeed(0)
                        setScript(ScriptID(702 4))
                    )
                    (sewer:status(4))
                )
                (if (((== (sewer:status) 3) and (== (sewer:location) 110)) and (< (sewer:prevDistance) 40))
                    (send (ScriptID(702 2)):
                        init()
                        hide()
                        posn(359 125)
                        setLoop(2)
                        moveSpeed(0)
                        setScript(ScriptID(702 4))
                    )
                    (sewer:location(105))
                )(else
                    (if (<> (sewer:location) 105)
                        (send gLongSong2:
                            vol(0)
                            fade(0 10 10 0)
                        )
                        (send gLongSong:
                            vol(127)
                            playBed()
                        )
                    )
                )
            )
            (case 1
                proc0_1()
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance enterNorth of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    posn(194 32)
                    setLoop(5)
                    ignoreActors(1)
                    illegalBits(0)
                    setMotion(PolyPath 156 62 self)
                )
                (if (== (sewer:status) 3)
                    (switch ((sewer:location))
                        (case 105
                            (send (ScriptID(702 2)):
                                init()
                                hide()
                                setLoop(0)
                                posn(118 85)
                                setScript(ScriptID(702 4))
                            )
                            = state 1
                        )
                        (case 90
                            (send (ScriptID(702 2)):
                                init()
                                hide()
                                setLoop(0)
                                posn(256 65510)
                            )
                            = seconds 2
                            = local0 1
                        )
                    )
                )(else
                    = state 1
                )
            )
            (case 2
                proc0_1()
                proc0_3()
                (if (local0)
                    (send (ScriptID(702 2)):
                        posn(240 65520)
                        setScript(ScriptID(702 4))
                    )
                    (sewer:location(105))
                )
                (self:dispose())
            )
        )
    )

)
(instance slimeLeavingR of Script
    (properties)

    (method (changeState newState)
        (var temp0[2])
        (switch (= state newState)
            (case 0
                (send (ScriptID(702 2)):setMotion(MoveTo 360 125 self))
            )
            (case 1
                (send (ScriptID(702 2)):dispose())
                (sewer:location(110))
                (self:dispose())
            )
        )
    )

)
(instance slimeLeavingUp of Script
    (properties)

    (method (changeState newState)
        (var temp0[2])
        (switch (= state newState)
            (case 0
                (send (ScriptID(702 2)):setMotion(MoveTo 225 65529 self))
                (send gLongSong:
                    vol(0)
                    fade(0 10 10 0)
                )
                (send gLongSong2:
                    vol(127)
                    number(819)
                    loop(1)
                    play()
                )
            )
            (case 1
                (send (ScriptID(702 2)):dispose())
                (sewer:
                    location(90)
                    status(6)
                    rmTimer(0)
                )
                (send gLongSong:
                    vol(127)
                    playBed()
                )
                (send gLongSong2:
                    vol(0)
                    fade(0 10 10 0)
                )
                (self:dispose())
            )
        )
    )

)
