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


(local
    local0
    local1

)
(instance public Room90 of Rm
    (properties
        picture 90
        style 16
    )

    (method (init)
        Load(rsSCRIPT 991)
        Load(rsVIEW 634)
        Load(rsVIEW 512)
        Load(rsSOUND 51)
        (self:setRegions(604))
        (super:init())
        proc0_12(604 0)
        (send ((View:new())):
            view(634)
            loop(1)
            cel(1)
            posn(209 78)
            setPri(4)
            init()
            addToPic()
        )
        (send ((Prop:new())):
            view(512)
            loop(0)
            posn(209 66)
            setPri(3)
            init()
            setCycle(Fwd)
        )
        (if ((== gPicture 91) or (== gPicture 0))
            (send gEgo:
                posn(255 135)
                baseSetter(0)
                view(4)
                setStep(4 1)
                illegalBits(49152)
                init()
            )
            = local0 0
            (if (global175)
                Print(90 0 134 -1 20 66 global23)
                = global175 0
            )
        )
        (if (== gPicture 85)
            (send gEgo:
                posn(104 39)
                baseSetter(ScriptID(0 1))
                view(4)
                setStep(4 1)
                illegalBits(32768)
                setPri(12)
                init()
            )
            = local0 1
        )
    )


    (method (doit)
        (if (& (send gEgo:onControl(0)) $0040)
            (send gEgo:
                setPri(-1)
                illegalBits(32768)
                baseSetter(0)
            )
            (send global2:newRoom(91))
        )
        (if (& (send gEgo:onControl(0)) $0020)
            (send gEgo:
                setPri(-1)
                illegalBits(32768)
                baseSetter(0)
            )
            (send global2:newRoom(85))
        )
        (if ((<> (self:script()) fallingToDeath) and (<> (self:script()) fallingDown))
            (if (local0)
                (if (& (send gEgo:onControl()) $0004)
                    (self:setScript(fallingToDeath))
                )(else
                    (if (& (send gEgo:onControl()) $0100)
                        (self:setScript(fallingDown))
                    )
                )
            )
            (if (& (send gEgo:onControl(1)) $0002)
                (if ((< (send gEgo:heading()) 180) and (> (send gEgo:heading()) 0))
                    (send gEgo:
                        baseSetter(ScriptID(0 1))
                        setPri(-1)
                        illegalBits(49152)
                    )
                    = local0 0
                )(else
                    (send gEgo:
                        baseSetter(0)
                        illegalBits(32768)
                        setPri(12)
                    )
                    = local0 1
                )
            )
        )
        (super:doit())
    )


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


    (method (handleEvent pEvent)
        return 
            (if ((send pEvent:claimed()))
                return 1
            )(else
                (if ((== (send pEvent:type()) 128) and Said('look>'))
                    (if (Said('/dirt') or Said('<down'))
                        Print(90 1)
                    )(else
                        (if (Said('/wall'))
                            Print(90 2)
                        )(else
                            (if (Said('/sky') or Said('<up'))
                                Print(90 3)
                            )(else
                                (if (Said('/stair'))
                                    Print(90 4)
                                )(else
                                    (if (Said('/stair'))
                                        Print(90 5)
                                    )(else
                                        (if (Said('/door'))
                                            Print(90 6)
                                        )(else
                                            (if (Said('/door'))
                                                Print(90 7)
                                            )(else
                                                (if (Said('[<around][/room]') or Said('/castle,tower'))
                                                    Print(90 8)
                                                )(else
                                                    (send pEvent:claimed(0))
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )

)
(instance fallingDown of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((User:
                    canInput(0)
                    canControl(0)
                )
 (send gEgo:
                    view(44)
                    loop(0)
                    illegalBits(0)
                    setPri(9)
                    setCycle(End)
                    setMotion((send ((Jump:new())):
                            y(145)
                            gx(2)
                            gy(
                                (if (>= (send gEgo:y()) 145)
                                    65531
                                )(else
                                    5
                                )
)
                        )
 self)
                )
 (send local1:
                    number(51)
                    loop(1)
                    play()
                )
  )
            )
            (case 1
                ((send gEgo:
                    view(41)
                    loop(0)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 2
                ((send gEgo:
                    view(4)
                    baseSetter(0)
                    illegalBits(49152)
                    setPri(-1)
                    setCycle(Walk)
                )
 = local0 0 (send local1:dispose()) (User:
                    canInput(1)
                    canControl(1)
                )
 (send client:setScript(0)) = state -1 )
            )
        )
    )

)
(instance fallingToDeath of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((User:
                    canInput(0)
                    canControl(0)
                )
 = global105 16 (send gEgo:
                    view(44)
                    loop(2)
                    illegalBits(0)
                    setPri(9)
                    setMotion((send ((Jump:new())):
                            y(145)
                            gx(2)
                            gy(5)
                        )
 self)
                )
 (send ((Sound:new())):
                    number(51)
                    loop(1)
                    play()
                )
  )
            )
            (case 1
                ((send gEgo:view(42)) proc0_20() kernel[106](5) = seconds 2  )
            )
            (case 2
                ((send gSounds:eachElementDo(172)) = global127 1 (send client:setScript(0)) )
            )
        )
    )

)
