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


(local
    local0
    newAct

)
(instance theMusic of Sound
    (properties)
)
(instance fallMusic of Sound
    (properties)
)
(instance public Room93 of Rm
    (properties
        picture 93
        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(0)
            posn(101 76)
            setPri(4)
            init()
            addToPic()
        )
        (send ((Prop:new())):
            view(512)
            loop(0)
            posn(103 64)
            setPri(3)
            init()
            setCycle(Fwd)
        )
        (send gEgo:baseSetter(ScriptID(0 1)))
        (if ((== gPicture 92) or (== gPicture 0))
            (send gEgo:
                posn(73 138)
                view(4)
                setStep(4 1)
                illegalBits(49152)
                baseSetter(0)
                init()
                observeBlocks(stair1 stair2)
            )
            = local0 0
            (if (global175)
                (if (> Random(0 100) 90)
                    Print(93 0 134 -1 20 66 global23)
                    = global175 0
                )(else
                    (send (= newAct (Act:new())):
                        view(141)
                        illegalBits(0)
                        ignoreActors()
                        posn(45 135)
                        setStep(6 4)
                        setCycle(Walk)
                        setScript(henchChase93)
                        init()
                    )
                )
            )
        )
        (if (== gPicture 88)
            (send gEgo:
                posn(195 26)
                view(4)
                setStep(4 1)
                setPri(12)
                baseSetter(ScriptID(0 1))
                illegalBits(32768)
                init()
                observeBlocks(stair1 stair2)
            )
            = local0 1
        )
    )


    (method (doit)
        (if (& (send gEgo:onControl(0)) $0040)
            (send gEgo:illegalBits(32768))
            (send global2:newRoom(92))
        )
        (if (& (send gEgo:onControl(0)) $0020)
            (send gEgo:
                setPri(-1)
                illegalBits(32768)
            )
            (send global2:newRoom(88))
        )
        (if ((local0 and (<> (send gEgo:script()) falling)) and (& (send gEgo:onControl(0)) $0004))
            (send gEgo:setScript(falling))
        )
        (if ((& (send gEgo:onControl(1)) $0002) and (<> (send gEgo:script()) falling))
            (if ((< (send gEgo:heading()) 180) and (> (send gEgo:heading()) 0))
                (send gEgo:
                    setPri(12)
                    illegalBits(32768)
                    baseSetter(ScriptID(0 1))
                )
                = local0 1
            )(else
                (send gEgo:
                    setPri(-1)
                    illegalBits(49152)
                    baseSetter(0)
                )
                = local0 0
            )
        )
        (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)
                    (if (Said('look[<around][/!*]') or Said('look/room,castle,tower'))
                        Print(93 1)
                    )(else
                        (if (Said('look>'))
                            (if (Said('/stair'))
                                Print(93 2)
                            )(else
                                (if (Said('/dirt') or Said('<down'))
                                    Print(93 3)
                                )(else
                                    (if (Said('/sky') or Said('<up'))
                                        Print(93 4)
                                    )(else
                                        (if (Said('/stair'))
                                            Print(93 5)
                                        )(else
                                            (if (Said('/door'))
                                                Print(93 6)
                                            )(else
                                                (if (Said('/door'))
                                                    Print(93 7)
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )

)
(instance falling of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((User:
                    canControl(0)
                    canInput(0)
                )
 
                (if (> (send gEgo:y()) 110)
                    (self:changeState(10))
                )(else
                    (self:changeState(20))
                )
 )
            )
            (case 10
                ((send gEgo:
                    view(44)
                    baseSetter(0)
                    setStep(8 3)
                    setLoop(1)
                    illegalBits(0)
                    setPri(9)
                    setCycle(End)
                )
 
                (if (<= (send gEgo:y()) 135)
                    (send gEgo:setMotion(JumpTo 137 145 self))
                )(else
                    (send gEgo:setMotion(MoveTo 137 145 self))
                )
 (fallMusic:
                    number(51)
                    loop(1)
                    play()
                )
  )
            )
            (case 11
                ((send gEgo:
                    view(41)
                    cel(0)
                    setPri(-1)
                    setCycle(End self)
                )
  )
            )
            (case 12
                ((send gEgo:
                    view(4)
                    setStep(4 1)
                    setLoop(-1)
                    illegalBits(49152)
                    setPri(-1)
                    setCycle(Walk)
                )
 = local0 0 (fallMusic:dispose()) (User:
                    canInput(1)
                    canControl(1)
                )
 (send client:setScript(0))  )
            )
            (case 20
                ((User:
                    canInput(0)
                    canControl(0)
                )
 = global105 16 (send gEgo:
                    view(44)
                    illegalBits(0)
                    baseSetter(0)
                    setPri(9)
                    setMotion((send ((Jump:new())):
                            y(
                                (if (<= (send gEgo:y()) 145)
                                    145
                                )(else
                                    (send gEgo:y())
                                )
)
                            gy(4)
                            gx(
                                (if (< (send gEgo:y()) 60)
                                    -1
                                )(else
                                    65534
                                )
)
                        )
 self)
                )
 (fallMusic:
                    number(51)
                    loop(1)
                    play()
                )
  )
            )
            (case 21
                ((send gEgo:
                    view(42)
                    setPri(3)
                )
 proc0_20() kernel[106](5) = seconds 4  )
            )
            (case 22
                (= global127 1 (fallMusic:dispose()) (send client:setScript(0)) )
            )
        )
    )

)
(instance henchChase93 of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((theMusic:
                    number(41)
                    loop(1)
                    play()
                )
 (send newAct:setMotion(Chase gEgo 15 self))  )
            )
            (case 1
                ((User:
                    canControl(0)
                    canInput(0)
                )
 (send gEgo:
                    moveSpeed(0)
                    setMotion(0)
                )
 (theMusic:
                    number(42)
                    loop(1)
                    play()
                )
 = seconds 4  )
            )
            (case 2
                (= global205 1 (send global2:newRoom(81)) )
            )
        )
    )

)
(instance stair1 of Blk
    (properties
        top 127
        left 192
        bottom 129
        right 194
    )
)
(instance stair2 of Blk
    (properties
        top 144
        left 167
        bottom 146
        right 169
    )
)
