(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "Sound")
(use "Cycle")
(use "Game")
(use "User")
(use "PV")
(use "Obj")
(script 85)



(instance fallMusic of Sound
    (properties)
)
(instance public Room85 of Rm
    (properties
        picture 85
        style 16
    )

    (method (init)
        Load(rsVIEW 634)
        Load(rsVIEW 512)
        (self:setRegions(604))
        (super:init())
        (send ((View:new())):
            view(634)
            loop(1)
            cel(1)
            posn(223 164)
            setPri(12)
            addToPic()
        )
        (send ((Prop:new())):
            view(512)
            loop(0)
            cel(4)
            posn(223 152)
            setPri(11)
            init()
            setCycle(Fwd)
        )
        (if ((== gPicture 90) or (== gPicture 0))
            (send gEgo:
                posn(117 170)
                view(4)
                baseSetter(ScriptID(0 1))
                setStep(4 1)
                init()
            )
        )
        (if (== gPicture 81)
            (send gEgo:
                posn(131 36)
                view(4)
                baseSetter(ScriptID(0 1))
                looper(myLooper)
                setLoop(-1)
                setStep(4 1)
                init()
            )
        )
    )


    (method (doit)
        (super:doit())
        (if (& (send gEgo:onControl(0)) $0040)
            (send gEgo:
                baseSetter(0)
                looper(0)
            )
            (send global2:newRoom(90))
        )
        (if (& (send gEgo:onControl(0)) $0020)
            (send gEgo:
                baseSetter(0)
                looper(0)
            )
            (send global2:newRoom(81))
        )
        (if ((& (send gEgo:onControl()) $0004) and (<> (self:script()) fallStairs))
            (self:setScript(fallStairs))
        )
        (if (& (send gEgo:onControl(0)) $0002)
            (send gEgo:looper(myLooper))
        )(else
            (if (> (send gEgo:y()) 110)
                (send gEgo:looper(0))
            )
        )
    )


    (method (dispose)
        (send gSounds:eachElementDo(172))
        (super:dispose())
    )


    (method (handleEvent pEvent)
        return 
            (if ((send pEvent:claimed()))
                return 1
            )(else
                (if (== (send pEvent:type()) 128)
                    (if (Said('look[<around][/!*]') or Said('look/room,tower,castle'))
                        Print(85 0)
                    )(else
                        (if (Said('look>'))
                            (if (Said('/dirt') or Said('<down'))
                                Print(85 1)
                            )(else
                                (if (Said('/sky') or Said('<up'))
                                    Print(85 2)
                                )(else
                                    (if (Said('/stair'))
                                        Print(85 3)
                                    )(else
                                        (if (Said('/stair'))
                                            Print(85 4)
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )

)
(instance myLooper of Code
    (properties)

    (method (doit param1)
        (send param1:loop(
            (if ((>= (send param1:heading()) 305) or (<= (send param1:heading()) 45))
                2
            )(else
                (if ((>= (send param1:heading()) 135) and (<= (send param1:heading()) 225))
                    3
                )(else
                    (if ((> (send param1:heading()) 45) and (< (send param1:heading()) 135))
                        0
                    )(else
                        1
                    )
                )
            )
))
    )

)
(instance fallStairs of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((User:
                    canControl(0)
                    canInput(0)
                )
 = global105 16 (send gEgo:
                    view(44)
                    illegalBits(0)
                    ignoreActors(1)
                    moveSpeed(0)
                    setLoop(
                        (if (== (send gEgo:loop()) 1)
                            1
                        )(else
                            0
                        )
)
                    setCycle(End self)
                )
 (fallMusic:
                    number(52)
                    loop(1)
                    play()
                )
  )
            )
            (case 1
                ((send gEgo:
                    setStep(10 10)
                    setLoop(+ 2 (send gEgo:loop()))
                    setCycle(Fwd)
                    setPri(-1)
                    setMotion(MoveTo 
                        (if (< (send gEgo:y()) 130)
                            - (send gEgo:x()) 20
                        )(else
                            + (send gEgo:x()) 10
                        )
 220 self)
                )
  )
            )
            (case 2
                ((send gCast:eachElementDo(256)) DrawPic(90) (send ((View:new())):
                    view(634)
                    loop(1)
                    cel(1)
                    posn(209 78)
                    setPri(4)
                    addToPic()
                )
 (send ((Prop:new())):
                    view(512)
                    loop(0)
                    posn(209 66)
                    setPri(3)
                    init()
                    setCycle(Fwd)
                )
 
                (if (global169)
                    (send ((View:new())):
                        view(145)
                        ignoreActors(1)
                        loop(4)
                        cel(0)
                        posn(188 128)
                        init()
                        addToPic()
                    )
                )
 (send gEgo:
                    show()
                    posn(190 10)
                    setStep(10 30)
                    setMotion(MoveTo 190 147 self)
                )
  )
            )
            (case 3
                ((send gEgo:
                    view(42)
                    loop(
                        (if (== (send gEgo:loop()) 2)
                            0
                        )(else
                            1
                        )
)
                )
 proc0_20() (fallMusic:dispose()) kernel[106](5) = seconds 4  )
            )
            (case 4
                (= global127 1 (send client:setScript(0)) )
            )
        )
    )

)
