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


(local
    newProp[9]
    local9
    newProp_2
    local11
    newProp_3

)
(instance gMusic of Sound
    (properties)
)
(instance walkingMusic of Sound
    (properties)
)
(instance public Room5 of Rm
    (properties
        picture 5
    )

    (method (init)
        = north 29
        = south 11
        = east 6
        = west 4
        = horizon 86
        = global101 0
        (if (global100)
            = picture 105
        )
        (send gEgo:edgeHit(0))
        (self:setRegions(509))
        (super:init())
        = local9 1
        (while (<= local9 7)
            = newProp[local9] (Prop:new())
            ++local9
        )
        (send newProp[1]:
            view(690)
            loop(0)
            cel(0)
            cycleSpeed(1)
            ignoreActors()
            posn(270 81)
            setPri(15)
            init()
            stopUpd()
        )
        (send newProp[2]:
            view(690)
            loop(1)
            cel(0)
            cycleSpeed(1)
            ignoreActors()
            posn(270 81)
            setPri(15)
            init()
            stopUpd()
        )
        (send newProp[3]:
            view(690)
            loop(2)
            cel(0)
            cycleSpeed(1)
            ignoreActors()
            posn(291 78)
            setPri(8)
            init()
            stopUpd()
        )
        (send newProp[4]:
            view(690)
            loop(3)
            cel(0)
            cycleSpeed(1)
            ignoreActors()
            posn(311 110)
            setPri(7)
            init()
            stopUpd()
        )
        (send newProp[5]:
            view(690)
            loop(3)
            cel(0)
            cycleSpeed(1)
            ignoreActors()
            posn(266 59)
            setPri(2)
            init()
            stopUpd()
        )
        (send newProp[6]:
            view(691)
            loop(0)
            cel(0)
            cycleSpeed(1)
            ignoreActors()
            posn(115 76)
            setPri(8)
            init()
            stopUpd()
        )
        (send newProp[7]:
            view(691)
            loop(1)
            cel(0)
            cycleSpeed(1)
            ignoreActors()
            posn(235 162)
            setPri(15)
            init()
            stopUpd()
        )
        = newProp_2 (Prop:new())
        = newProp_3 (Prop:new())
        (send newProp_2:
            view(689)
            loop(0)
            cel(3)
            ignoreActors()
            posn(208 57)
            setPri(15)
            setCycle(Fwd)
            cycleSpeed(4)
            init()
        )
        (send newProp_3:
            view(689)
            loop(1)
            cel(0)
            ignoreActors()
            posn(233 44)
            setPri(15)
            setCycle(Fwd)
            cycleSpeed(3)
            init()
        )
        (switch (gPicture)
            (case 4
                (
                (if (<= (send gEgo:y()) 135)
                    (send gEgo:posn(1 120))
                )(else
                    (send gEgo:posn(1 (send gEgo:y())))
                )
 )
            )
            (case 6
                (
                (if (< (send gEgo:y()) 133)
                    (send gEgo:posn(318 133))
                )(else
                    (send gEgo:posn(318 (send gEgo:y())))
                )
 )
            )
            (case 11
                (
                (if (> (send gEgo:x()) 207)
                    (send gEgo:posn(207 188))
                )(else
                    (send gEgo:posn((send gEgo:x()) 188))
                )
 )
            )
            (case 29
                (
                (if (> (send gEgo:x()) 272)
                    (send gEgo:x(258))
                )
 (send gEgo:posn((send gEgo:x()) (+ horizon (send gEgo:yStep()))))  )
            )
            (case 0
                ((send gEgo:
                    x(290)
                    y(160)
                )
 )
            )
        )
        (walkingMusic:
            number(64)
            play()
        )
        (send gEgo:
            view(2)
            init()
        )
    )


    (method (doit)
        (super:doit())
        (if (not global112 and (== (send global2:script()) 0))
            (if (& (send gEgo:onControl(0)) $0040)
                = local11 3
                = local9 1
                (send global2:setScript(grabbed))
            )(else
                (if (& (send gEgo:onControl(0)) $0020)
                    = local11 3
                    = local9 2
                    (send global2:setScript(grabbed))
                )(else
                    (if (& (send gEgo:onControl(0)) $0010)
                        = local11 3
                        = local9 3
                        (send global2:setScript(grabbed))
                    )(else
                        (if (& (send gEgo:onControl(0)) $0004)
                            = local11 1
                            = local9 7
                            (send global2:setScript(grabbed))
                        )(else
                            (if (& (send gEgo:onControl(0)) $0400)
                                = local11 1
                                = local9 4
                                (send global2:setScript(grabbed))
                            )(else
                                (if (& (send gEgo:onControl(0)) $0200)
                                    = local11 1
                                    = local9 5
                                    (send global2:setScript(grabbed))
                                )(else
                                    (if (& (send gEgo:onControl(0)) $0002)
                                        = local11 2
                                        = local9 6
                                        (send global2:setScript(grabbed))
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )


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


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed()))
            return 1
        )
        return 
            (if (== (send pEvent:type()) 128)
                (if ((Said('look/room') or Said('look/around')) or Said('look[<around][/!*]'))
                    Print(5 0)
                )(else
                    (if (Said('look/cottage'))
                        Print(5 1)
                    )(else
                        (if (Said('look/door'))
                            Print(5 2)
                        )(else
                            (if (Said('look/window'))
                                (if ((send gEgo:inRect(0 130 32 138)))
                                    Print(5 3)
                                )(else
                                    Print(5 4)
                                )
                            )(else
                                (if (Said('break/window'))
                                    Print(5 5)
                                )(else
                                    (if (Said('open/window'))
                                        Print(5 6)
                                    )
                                )
                            )
                        )
                    )
                )
            )(else
                0
            )
    )

)
(instance grabbed of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((walkingMusic:dispose()) (gMusic:
                    number(65)
                    play()
                )
 proc0_10() (send newProp[local9]:setCycle(CT local11 1 self))  )
            )
            (case 1
                ((send gEgo:dispose()) (send newProp[local9]:setCycle(End self))  )
            )
            (case 2
                (
                (switch (Random(1 6))
                    (case 1
                        (Print(5 7)  )
                    )
                    (case 2
                        (Print(5 8)  )
                    )
                    (case 3
                        (Print(5 9)  )
                    )
                    (case 4
                        (Print(5 10)  )
                    )
                    (case 5
                        (Print(5 11)  )
                    )
                    (case 6
                        (Print(5 12) )
                    )
                )
 = seconds 5  )
            )
            (case 3
                (= global127 1 )
            )
        )
    )

)
