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


(local
    local0

)
(instance public Room61 of Rm
    (properties
        picture 61
        style 16
    )

    (method (init)
        Load(rsSOUND 51)
        Load(rsVIEW 44)
        Load(rsVIEW 42)
        Load(rsPIC 66)
        (self:setRegions(603))
        (super:init())
        = global101 1
        (if (== gPicture 66)
            (send gEgo:
                posn(111 172)
                view(4)
                loop(0)
                baseSetter(ScriptID(0 1))
                xStep(4)
                yStep(1)
                setPri(12)
                illegalBits(32768)
                init()
            )
        )
        (if (== gPicture 58)
            (send gEgo:
                posn(155 45)
                view(4)
                baseSetter(ScriptID(0 1))
                looper(myLooper)
                xStep(4)
                yStep(1)
                illegalBits(32768)
                init()
            )
        )
    )


    (method (doit)
        (super:doit())
        (if ((& (send gEgo:onControl(0)) $0040) and (== (send gEgo:script()) 0))
            (send gEgo:looper(0))
            (send global2:newRoom(66))
        )
        (if ((& (send gEgo:onControl(0)) $0020) and (== (send gEgo:script()) 0))
            (send gEgo:looper(0))
            (send global2:newRoom(58))
        )
        (if ((& (send gEgo:onControl(0)) $0004) and (== (send gEgo:script()) 0))
            (send gEgo:setScript(fallStairs))
        )
        (if (& (send gEgo:onControl(0)) $0200)
            (send gEgo:looper(myLooper))
        )(else
            (if ((> (send gEgo:y()) 130) and (<> (send gEgo:script()) fallStairs))
                (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) and Said('look>'))
                    (if (Said('/stair'))
                        Print(61 0)
                    )(else
                        (if (Said('/dirt'))
                            Print(61 1)
                        )(else
                            (if (Said('/wall'))
                                Print(61 2)
                            )(else
                                (if (Said('<up[/!*]'))
                                    Print(61 3)
                                )(else
                                    (if (Said('<down[/!*]'))
                                        Print(61 1)
                                    )(else
                                        (if (Said('[<around][/room,tower]'))
                                            Print(61 4)
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )

)
(instance myLooper of Code
    (properties)

    (method (doit param1)
        (send param1:loop(
            (if ((>= (send param1:heading()) 335) or (<= (send param1:heading()) 25))
                2
            )(else
                (if ((>= (send param1:heading()) 155) and (<= (send param1:heading()) 205))
                    3
                )(else
                    (if ((> (send param1:heading()) 25) and (< (send param1:heading()) 155))
                        0
                    )(else
                        1
                    )
                )
            )
))
    )

)
(instance fallStairs of Script
    (properties)

    (method (doit)
        (if ((== (send global2:picture()) 61) and (> (send gEgo:y()) 100))
            (send gEgo:setPri(14))
        )
        (super:doit())
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= local0 Print(61 5 134 -1 20 172) (User:canControl(0)) (send ((Sound:new())):
                    number(51)
                    loop(1)
                    play()
                )
 (send gEgo:
                    illegalBits(0)
                    ignoreActors(1)
                )
 (self:cue())  )
            )
            (case 1
                ((send gEgo:
                    view(44)
                    moveSpeed(0)
                    setPri(13)
                    setCycle(End self)
                )
  )
            )
            (case 2
                ((send gEgo:
                    xStep(5)
                    yStep(20)
                    setCycle(Fwd)
                    setPri(-1)
                    setMotion(MoveTo 
                        (if (< (send gEgo:y()) 130)
                            - (send gEgo:x()) 20
                        )(else
                            + (send gEgo:x()) 20
                        )
 255 self)
                )
  )
            )
            (case 3
                ((send gEgo:posn(195 10)) (send global2:drawPic(66)) (send gSounds:eachElementDo(172)) (send ((Sound:new())):
                    number(51)
                    loop(1)
                    play()
                )
 (send gEgo:
                    setPri(-1)
                    setMotion(MoveTo 200 137 self)
                )
  )
            )
            (case 4
                (
                (if (gTheNewDialog)
                    (send gTheNewDialog:dispose())
                )
 (send gEgo:
                    view(42)
                    loop(% (send gEgo:loop()) 2)
                    baseSetter(0)
                    setPri(3)
                )
 (send (ScriptID(0 4)):setCycle(self 1))  )
            )
            (case 5
                (kernel[106](10) Animate((send gCast:elements()) 0) = seconds 4  )
            )
            (case 6
                (= global127 1 )
            )
        )
    )

)
