(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "sewer")
(use "SQRoom")
(use "Polygon")
(use "Cycle")
(use "PicView")
(use "Obj")
(script 85)



(instance public rm085 of SQRoom
    (properties
        picture 85
        south 100
        west 80
        picAngle 70
        vanishingX 0
        vanishingY 65496
    )

    (method (init)
        (sewer:roomVer(22891))
        Load(rsVIEW 85)
        Load(rsVIEW 80)
        Load(rsSOUND 810)
        Load(rsSOUND 811)
        (switch (global12)
            (case west
                proc0_3()
                (send gEgo:y(100))
                (self:style(41))
                (send (ScriptID(702 3)):
                    init()
                    hide()
                    setScript(dripScript)
                )
            )
            (case south
                (if ((((<> global12 100) and (== (sewer:location) 0)) and (== (sewer:status) 0)) and (> Random(0 100) 50))
                    (send (ScriptID(702 3)):
                        init()
                        hide()
                        setScript(dripScript)
                    )
                )(else
                    (if (== (sewer:location) 85)
                        (if (== (sewer:status) 6)
                            (send (ScriptID(702 2)):
                                init()
                                hide()
                                setLoop(1)
                                posn(190 109)
                                setCycle(Fwd)
                                setScript(ScriptID(702 4))
                            )
                            (sewer:status(4))
                        )
                        (if (== (sewer:status) 8)
                            (if (> Random(0 100) 50)
                                (send (ScriptID(702 2)):
                                    init()
                                    hide()
                                    setLoop(2)
                                    posn(65521 91)
                                    setCycle(Fwd)
                                    setScript(slimeLeaving)
                                )
                            )(else
                                (send (ScriptID(702 2)):
                                    init()
                                    hide()
                                    setLoop(1)
                                    posn(176 97)
                                    setCycle(Fwd)
                                    setScript(ScriptID(702 4))
                                )
                                (sewer:status(4))
                            )
                        )
                    )
                )
                (self:
                    setScript(enterScript)
                    style(30)
                )
            )
            (default 
                (send (ScriptID(702 3)):
                    init()
                    hide()
                    setScript(dripScript)
                )
                (send gEgo:view(0))
                (send gLongSong:flags(1))
                (send gLongSong2:flags(1))
                (self:setScript(enterDoor))
            )
        )
        (door:
            init()
            setPri(10)
        )
        (send gEgo:
            init()
            setPri(-1)
        )
        (send (ScriptID(702 5)):
            init()
            setLoop(5)
            posn(311 144)
            setScript(daDripScript)
        )
        (send (ScriptID(702 6)):
            init()
            setLoop(4)
            posn(177 69)
            setScript(daDripScript2)
        )
        (super:init())
        (send gEgo:show())
        (send (ScriptID(702 2)):show())
        (self:
            setRegions(702)
            addObstacle((send ((Polygon:new())):
                    type(2)
                    init(0 100 160 100 271 189 0 189)
                    yourself()
                )
 (send ((Polygon:new())):
                    type(2)
                    init(0 0 319 0 319 189 286 189 181 102 165 92 151 89 0 89)
                    yourself()
                )
)
        )
    )


    (method (doit param1)
        (if (script)
            0
        )(else
            (if (== (send gEgo:edgeHit) 3)
                proc0_2()
                (self:setScript(exitSouth))
            )
        )
        (super:doit(rest param1))
    )

)
(instance door of Prop
    (properties)

    (method (doVerb param1 param2 param3)
        (switch (param1)
            (case 2
                Print("This hatch opens from the other side only.")
            )
            (case 4
                Print("Nobody can hear you through the thick door.")
            )
            (default 
                (super:doVerb(param1 rest param3))
            )
        )
    )

)
(instance enterScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    illegalBits(0)
                    x(334)
                    y(240)
                    setLoop(7)
                    setMotion(MoveTo 280 186 self)
                )
            )
            (case 1
                proc0_1()
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance dripScript of Script
    (properties)

    (method (changeState newState)
        (var temp0[2])
        (switch (= state newState)
            (case 0
                = seconds Random(2 5)
            )
            (case 1
                (if (> (send gEgo:y) 162)
                    (sewer:
                        location(85)
                        status(2)
                        distance(300)
                    )
                    (send gLongSong:
                        vol(0)
                        fade(0 10 10 0)
                    )
                    (send gLongSong2:
                        vol(127)
                        number(806)
                        loop(1)
                        play()
                    )
                    (send (ScriptID(702 3)):
                        show()
                        setLoop(6)
                        posn(238 91)
                        cel(0)
                        cycleSpeed(1)
                        setCycle(CT 9 1 self)
                    )
                )(else
                    (self:init())
                )
            )
            (case 2
                (send (ScriptID(702 3)):setCycle(End))
                (send (ScriptID(702 2)):
                    init()
                    setLoop(8)
                    cycleSpeed(1)
                    setCycle(End self)
                    posn(214 124)
                )
            )
            (case 3
                (sewer:status(3))
                (send gLongSong2:
                    vol(127)
                    number(819)
                    loop(-1)
                    playBed()
                )
                (send (ScriptID(702 2)):
                    setLoop(1)
                    setCycle(Fwd)
                    cycleSpeed(0)
                    setScript(ScriptID(702 4))
                )
                (self:dispose())
            )
        )
    )

)
(instance exitSouth of Script
    (properties)

    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    setLoop(-1)
                    setHeading(130 self)
                )
            )
            (case 1
                (send gEgo:
                    setLoop(4)
                    setMotion(MoveTo 327 237 self)
                )
            )
            (case 2
                (if (== (sewer:location) 80)
                    (sewer:
                        status(0)
                        location(0)
                    )
                )
                (if ((((> Random(0 100) 60) and (== (sewer:location) 85)) and (== (sewer:status) 3)) and (< (send (ScriptID(702 2)):y) 135))
                    (sewer:status(8))
                )
                (send global2:newRoom(100))
            )
        )
    )

)
(instance enterDoor of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gLongSong:
                    vol(127)
                    number(805)
                    loop(-1)
                    playBed()
                )
                (send gEgo:
                    init()
                    hide()
                    posn(240 158)
                    setCycle(0)
                    setLoop(-1)
                    setHeading(270)
                )
                (door:
                    setCel(255)
                    cycleSpeed(1)
                )
                = cycles 1
            )
            (case 1
                (send gLongSong2:
                    vol(127)
                    number(810)
                    loop(1)
                    play()
                )
                = cycles 5
            )
            (case 2
                (door:setCycle(Beg self))
            )
            (case 3
                proc0_3()
                proc0_1()
                (send gLongSong2:
                    vol(127)
                    number(811)
                    play(self)
                )
            )
            (case 4
                Print("Oh, no! The door has shut and there's no way back... Now what are you going to do?")
                (self:dispose())
            )
        )
    )

)
(instance daDripScript of Script
    (properties)

    (method (changeState newState)
        (var temp0[2])
        (switch (= state newState)
            (case 0
                (send (ScriptID(702 5)):setCycle(End self))
            )
            (case 1
                = cycles Random(5 20)
            )
            (case 2
                (self:init())
            )
        )
    )

)
(instance daDripScript2 of Script
    (properties)

    (method (changeState newState)
        (var temp0[2])
        (switch (= state newState)
            (case 0
                (send (ScriptID(702 6)):setCycle(End self))
            )
            (case 1
                = cycles Random(5 20)
            )
            (case 2
                (self:init())
            )
        )
    )

)
(instance slimeLeaving of Script
    (properties)

    (method (changeState newState)
        (var temp0[2])
        (switch (= state newState)
            (case 0
                (send (ScriptID(702 2)):setMotion(MoveTo 65497 91 self))
            )
            (case 1
                (sewer:
                    location(80)
                    status(6)
                )
                (send (ScriptID(702 2)):
                    posn(1000 1000)
                    dispose()
                )
                (self:dispose())
            )
        )
    )

)
