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


(local
    gEgoOnControl
    local1
    local2
    theGEgoOnControl
    newView

)
(instance public Room28 of Rm
    (properties
        picture 28
    )

    (method (init)
        = north 22
        = south 4
        = east 29
        = west 27
        = horizon 126
        = global101 0
        (if (global100)
            = picture 128
        )
        (send gEgo:
            edgeHit(0)
            illegalBits(32768)
        )
        (super:init())
        (self:setRegions(508))
        Load(rsVIEW 17)
        Load(rsVIEW 21)
        Load(rsSOUND 51)
        = newView (View:new())
        (if (global100)
            (send newView:
                view(600)
                loop(0)
                cel(0)
                setPri(10)
                posn(289 139)
                init()
                stopUpd()
            )
        )(else
            (send newView:
                view(600)
                loop(1)
                cel(0)
                setPri(9)
                posn(283 139)
                ignoreActors()
                init()
                stopUpd()
            )
        )
        (switch (gPicture)
            (case 22
                ((send gEgo:posn(82 129))  )
            )
            (case 27
                (
                (if (<= (send gEgo:y()) horizon)
                    (send gEgo:posn(2 (+ horizon 2)))
                )(else
                    (send gEgo:posn(2 (send gEgo:y())))
                )
 )
            )
            (case 29
                (
                (if (<= (send gEgo:y()) 156)
                    (send gEgo:
                        x(318)
                        y(150)
                    )
                )(else
                    (send gEgo:posn(317 187))
                )
 )
            )
            (case 4
                ((send gEgo:posn(158 187))  )
            )
            (case 55
                ((send gEgo:
                    x(290)
                    y(135)
                )
  )
            )
            (case 0
                ((send gEgo:
                    x(88)
                    y(160)
                )
 )
            )
        )
        (send gEgo:
            view(2)
            xStep(2)
            yStep(1)
            init()
        )
        (send gEgo:y((| (send gEgo:y()) $0001)))
    )


    (method (doit)
        (super:doit())
        (if (& (= gEgoOnControl (send gEgo:onControl())) $0040)
            = gTheGGNewPropX 55
        )
        (if ((<> gEgoOnControl theGEgoOnControl) and (== (send global2:script()) 0))
            = theGEgoOnControl gEgoOnControl
            (if (& gEgoOnControl $0004)
                (self:setScript(fallSouth))
            )
        )
    )


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


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed()))
            return 1
        )
        return 
            (if (== (send pEvent:type()) 128)
                (if (not global100)
                    (if (Said('look>'))
                        (if (Said('/door'))
                            Print(28 0)
                        )(else
                            (if (Said('<in[/mine]'))
                                (if ((send gEgo:inRect(269 135 295 142)))
                                    Print(28 1)
                                )(else
                                    Print(800 1)
                                )
                            )(else
                                (if (Said('/mine,hill'))
                                    Print(28 2)
                                )(else
                                    (if (Said('[<around][/room]'))
                                        Print(28 3)
                                    )
                                )
                            )
                        )
                    )
                    (if (Said('/door>'))
                        (if (Said('close,close'))
                            Print(28 4)
                        )(else
                            (if (Said('open,bang'))
                                Print(28 5)
                            )
                        )
                    )
                )(else
                    (if (Said('/door,padlock,latch>'))
                        (if (Said('break/door'))
                            Print(28 6)
                        )(else
                            (if (Said('bang/door'))
                                (if ((send gEgo:inRect(276 131 298 143)))
                                    Print(28 7)
                                )(else
                                    Print(800 1)
                                )
                            )(else
                                (if (Said('open/door'))
                                    Print(28 8)
                                )(else
                                    (if (Said('unlatch,detach,get'))
                                        Print(28 9)
                                    )
                                )
                            )
                        )
                    )
                    (if (Said('look>'))
                        (if (Said('/door'))
                            Print(28 10)
                        )(else
                            (if (Said('/mine,hill'))
                                Print(28 11)
                            )(else
                                (if (Said('[<around][/room]'))
                                    Print(28 3)
                                )
                            )
                        )
                    )
                )
            )(else
                0
            )
    )

)
(instance fallSouth of Script
    (properties)

    (method (init)
        (send gEgo:viewer(0))
        (super:init())
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() (send ((Sound:new())):
                    number(51)
                    loop(1)
                    play()
                )
 
                (if (< (send gEgo:x()) 265)
                    = local2 20
                )(else
                    = local2 30
                )
 
                (if (> (+ (send gEgo:y()) local2) 188)
                    = local1 188
                )(else
                    = local1 (+ (send gEgo:y()) local2)
                )
 (send gEgo:
                    view(17)
                    setStep(6 6)
                    illegalBits(0)
                    loop(& (send gEgo:loop()) $0001)
                    setCel(0)
                    setCycle(End)
                    setMotion(MoveTo (send gEgo:x()) local1 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    xStep(2)
                    yStep(1)
                    view(21)
                    loop(2)
                    setCycle(CT 4 1 self)
                )
  )
            )
            (case 2
                ((send gEgo:
                    view(21)
                    loop(2)
                    setCycle(Beg self)
                )
  )
            )
            (case 3
                ((send global2:setScript(0)) (send gEgo:
                    illegalBits(32768)
                    setCycle(Walk)
                    view(2)
                )
 proc0_11() )
            )
        )
    )

)
