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


(local
    newAct
    newAct_2
    local2

)
(instance theMusic of Sound
    (properties)
)
(instance public Room46 of Rm
    (properties
        picture 46
        style 16
    )

    (method (init)
        Load(rsVIEW 632)
        Load(rsVIEW 110)
        Load(rsVIEW 114)
        (super:init())
        (if ((== gPicture 47) or (== gPicture 0))
            (send gEgo:
                view(4)
                baseSetter(ScriptID(0 1))
                posn(250 165)
                setStep(4 1)
                setPri(-1)
                init()
            )
            proc0_10()
        )
        (if (== gPicture 45)
            (send gEgo:
                view(4)
                baseSetter(ScriptID(0 1))
                posn(184 24)
                setStep(4 1)
                setPri(6)
                illegalBits(16384)
                init()
            )
        )
        (send (= newAct (Act:new())):
            view(111)
            posn(231 66)
            illegalBits(8192)
            setPri(14)
            xStep(1)
            yStep(3)
            setMotion(Wander 5)
            setCycle(Fwd)
            init()
        )
        (send (= newAct_2 (Act:new())):
            view(113)
            posn(132 145)
            illegalBits(8192)
            setPri(14)
            xStep(1)
            yStep(3)
            setMotion(Wander 5)
            setCycle(Fwd)
            init()
        )
        (theMusic:
            number(33)
            loop(1)
            play()
        )
        (send gEgo:observeBlocks(stairBlock1 stairBlock2 stairBlock3 stairBlock4))
    )


    (method (doit)
        (super:doit())
        (if (& (send gEgo:onControl(0)) $0040)
            (send gEgo:
                setPri(-1)
                baseSetter(0)
            )
            (send global2:newRoom(47))
        )
        (if (& (send gEgo:onControl(0)) $0020)
            proc0_11()
            (send gEgo:
                setPri(-1)
                illegalBits(32768)
                baseSetter(0)
            )
            (send global2:newRoom(45))
        )
        (if (& (send gEgo:onControl(0)) $0010)
            (if (> (send gEgo:heading()) 180)
                (send gEgo:
                    illegalBits(32768)
                    setPri(4)
                )
            )(else
                (send gEgo:
                    illegalBits(16384)
                    setPri(6)
                )
            )
        )
        (if (& (send gEgo:onControl(0)) $0008)
            (if (> (send gEgo:heading()) 180)
                (send gEgo:setPri(4))
            )(else
                (send gEgo:setPri(-1))
            )
        )
        (if (not local2 and ((& (send gEgo:onControl()) $0800) or (& (send gEgo:onControl(1)) $0400)))
            proc0_10()
            = local2 1
            (if (& (send gEgo:onControl()) $0800)
                (moveOnTheStairs:changeState(10))
            )(else
                (moveOnTheStairs:changeState(1))
            )
        )
    )


    (method (dispose)
        (theMusic:dispose())
        (super:dispose())
    )


    (method (handleEvent pEvent)
        return 
            (if ((send pEvent:claimed()))
                return 1
            )(else
                (if (== (send pEvent:type()) 128)
                    (if (Said('look>'))
                        (if (Said('<up[/!*]'))
                            Print(46 0)
                        )(else
                            (if (Said('<down[/!*]'))
                                Print(46 1)
                            )(else
                                (if (Said('[<up,down]/stair[<tower]'))
                                    Print(46 2)
                                )(else
                                    (if (Said('[<out,through]/window'))
                                        (if ((send gEgo:inRect(33 81 67 112)))
                                            Print(46 3)
                                        )(else
                                            Print(46 4)
                                        )
                                    )(else
                                        (if (Said('/wall'))
                                            Print(46 5)
                                        )(else
                                            (if (Said('[<down]/dirt'))
                                                Print(46 6)
                                            )(else
                                                (if (Said('/painting,tapestries'))
                                                    Print(46 7)
                                                )(else
                                                    (if (Said('/flora,blossom'))
                                                        Print(46 8)
                                                    )(else
                                                        (if (Said('/fairies[<little]'))
                                                            Print(46 9)
                                                        )(else
                                                            (if (Said('[<around][/room,tower]'))
                                                                Print(46 10)
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )(else
                        (if (Said('converse/fairies[<little]') or Said('converse[/!*]'))
                            Print(46 11)
                        )(else
                            (if (Said('kill/fairies[<little]'))
                                Print(46 12)
                            )(else
                                (if (Said('get/fairies[<little]'))
                                    Print(46 13)
                                )(else
                                    (if (Said('capture/fairies[<little]'))
                                        Print(46 13)
                                    )(else
                                        (if (Said('kiss/fairies[<little]') or Said('kiss[/!*]'))
                                            Print(46 14)
                                        )(else
                                            (if (Said('help/fairies[<little]'))
                                                Print(46 15)
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )

)
(instance stairBlock1 of Blk
    (properties
        top 83
        left 89
        bottom 85
        right 91
    )
)
(instance stairBlock2 of Blk
    (properties
        top 83
        left 115
        bottom 85
        right 117
    )
)
(instance stairBlock3 of Blk
    (properties
        top 93
        left 103
        bottom 95
        right 105
    )
)
(instance stairBlock4 of Blk
    (properties
        top 93
        left 75
        bottom 95
        right 77
    )
)
(instance moveOnTheStairs of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 1
                ((send gEgo:ignoreBlocks(stairBlock1 stairBlock2 stairBlock3 stairBlock4)) 
                (if (> (send gEgo:y()) 150)
                    (send gEgo:illegalBits(0))
                    (send gEgo:setMotion(MoveTo 199 133 self))
                )(else
                    (send gEgo:illegalBits(0))
                    (send gEgo:setMotion(MoveTo 261 170 self))
                )
 )
            )
            (case 2
                (
                (if (& (send gEgo:onControl()) $0040)
                    (send gEgo:
                        setPri(-1)
                        illegalBits(32768)
                        baseSetter(0)
                    )
                    proc0_11()
                    (send global2:newRoom(47))
                )(else
                    (send gEgo:observeBlocks(stairBlock1 stairBlock2 stairBlock3 stairBlock4))
                    (send gEgo:illegalBits(32768))
                    proc0_11()
                    = local2 0
                )
 )
            )
            (case 10
                ((send gEgo:ignoreBlocks(stairBlock1 stairBlock2 stairBlock3 stairBlock4)) 
                (if (< (send gEgo:y()) 50)
                    (send gEgo:illegalBits(0))
                    (send gEgo:setMotion(MoveTo 69 105 self))
                )(else
                    (send gEgo:illegalBits(0))
                    (send gEgo:setMotion(MoveTo 205 7 self))
                )
 )
            )
            (case 11
                ((send gEgo:observeBlocks(stairBlock1 stairBlock2 stairBlock3 stairBlock4)) 
                (if (& (send gEgo:onControl()) $0020)
                    (send gEgo:
                        setPri(-1)
                        illegalBits(32768)
                        baseSetter(0)
                    )
                    proc0_11()
                    (send global2:newRoom(45))
                )(else
                    proc0_11()
                    (send gEgo:illegalBits(32768))
                    = local2 0
                )
 )
            )
        )
    )

)
