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


(local
    newProp
    newProp_2
    newView
    newView_2
    gInvFirst
    local5
    local6
    local7

)
(procedure (localproc_000e)
    (var temp0)
    = temp0 0
    = gInvFirst (send gInv:first())
    (while (gInvFirst)
        (if ((= local5 NodeValue(gInvFirst)) and (== (send ((= local5 NodeValue(gInvFirst))):owner()) 89))
            = temp0 1
        )
        = gInvFirst (send gInv:next(gInvFirst))
    )
    return temp0
)


(instance public Room89 of Rm
    (properties
        picture 89
        style 16
    )

    (method (init)
        Load(rsVIEW 606)
        Load(rsVIEW 649)
        Load(rsVIEW 634)
        Load(rsVIEW 512)
        (self:setRegions(604))
        (super:init())
        (send ((View:new())):
            view(634)
            loop(1)
            cel(0)
            posn(57 89)
            setPri(6)
            init()
            addToPic()
        )
        (if (global100)
            (send ((Prop:new())):
                view(512)
                loop(0)
                posn(59 77)
                setPri(6)
                init()
                setCycle(Fwd)
            )
            (send ((View:new())):
                view(649)
                loop(2)
                cel(0)
                posn(264 106)
                setPri(7)
                init()
                addToPic()
            )
        )
        (send (= newProp (Prop:new())):
            view(606)
            loop(0)
            posn(222 109)
            init()
            setPri(8)
            stopUpd()
        )
        (send (= newProp_2 (Prop:new())):
            view(606)
            posn(96 109)
            loop(1)
            init()
            setPri(8)
            stopUpd()
        )
        (send (= newView (View:new())):
            view(606)
            posn(222 109)
            loop(2)
            cel(0)
            ignoreActors(1)
            init()
            stopUpd()
        )
        (if (not = local7 localproc_000e())
            (send newView:
                cel(2)
                forceUpd()
            )
        )
        (send (= newView_2 (View:new())):
            view(606)
            posn(96 109)
            loop(2)
            cel(1)
            ignoreActors(1)
            init()
            stopUpd()
        )
        (if ((== gPicture 91) or (== gPicture 0))
            (send gEgo:
                posn(38 152)
                view(4)
                xStep(4)
                yStep(1)
                init()
            )
            (if (global175)
                = global175 0
            )
        )
    )


    (method (doit)
        (super:doit())
        (if (& (send gEgo:onControl(0)) $0040)
            (send global2:newRoom(91))
        )
    )


    (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,kitchen'))
                        Print(89 0)
                    )(else
                        (if (Said('look>'))
                            (if (Said('<in/cabinet'))
                                (if ((< (send gEgo:distanceTo(newProp)) 25) or (< (send gEgo:distanceTo(newProp_2)) 25))
                                    (if (< (send gEgo:distanceTo(newProp)) 25)
                                        (if (== (send newProp:cel()) 0)
                                            (send newProp:setCycle(End rightCabinet))
                                        )
                                        (if (local7)
                                            Print(89 1)
                                        )(else
                                            Print(89 2)
                                        )
                                    )
                                    (if (< (send gEgo:distanceTo(newProp_2)) 25)
                                        (if (== (send newProp_2:cel()) 0)
                                            (send newProp_2:setCycle(End leftCabinet))
                                        )
                                        Print(89 3)
                                    )
                                )(else
                                    Print(800 1)
                                )
                            )(else
                                (if (Said('/cabinet'))
                                    Print(89 4)
                                )(else
                                    (if (Said('<under/table'))
                                        Print(89 5)
                                    )(else
                                        (if (Said('/table'))
                                            Print(89 6)
                                        )(else
                                            (if (Said('/fireplace'))
                                                Print(89 7)
                                            )(else
                                                (if (Said('/caldron'))
                                                    Print(89 8)
                                                )(else
                                                    (if (Said('/barrel'))
                                                        Print(89 9)
                                                    )(else
                                                        (if (Said('/wall'))
                                                            Print(89 10)
                                                        )(else
                                                            (if (Said('/dirt') or Said('<down'))
                                                                Print(89 11)
                                                            )(else
                                                                (if (Said('/window'))
                                                                    (if ((send gEgo:inRect(220 124 282 146)))
                                                                        Print(89 12)
                                                                    )(else
                                                                        Print(800 1)
                                                                    )
                                                                )(else
                                                                    (if (Said('/door'))
                                                                        Print(89 13)
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )(else
                            (if (Said('open>'))
                                (if (Said('/barrel'))
                                    Print(89 14)
                                )(else
                                    (if (Said('/window'))
                                        Print(89 15)
                                    )(else
                                        (if (Said('/cabinet,door'))
                                            (if (< (send gEgo:distanceTo(newProp)) 25)
                                                (if (== (send newProp:cel()) 0)
                                                    (send newProp:setCycle(End rightCabinet))
                                                    (if (local7)
                                                        Print(89 16)
                                                    )(else
                                                        Print(89 2)
                                                    )
                                                )(else
                                                    Print(89 17)
                                                )
                                            )(else
                                                (if (< (send gEgo:distanceTo(newProp_2)) 25)
                                                    (if (== (send newProp_2:cel()) 0)
                                                        (send newProp_2:setCycle(End leftCabinet))
                                                        Print(89 3)
                                                    )(else
                                                        Print(89 17)
                                                    )
                                                )(else
                                                    Print(800 1)
                                                )
                                            )
                                        )
                                    )
                                )
                            )(else
                                (if (Said('close/cabinet,door'))
                                    (if (< (send gEgo:distanceTo(newProp)) 25)
                                        (if ((send newProp:cel()))
                                            (send newProp:setCycle(Beg rightCabinet))
                                        )(else
                                            Print(89 18)
                                        )
                                    )(else
                                        (if (< (send gEgo:distanceTo(newProp_2)) 25)
                                            (if ((send newProp_2:cel()))
                                                (send newProp_2:setCycle(Beg leftCabinet))
                                            )(else
                                                Print(89 18)
                                            )
                                        )(else
                                            Print(800 1)
                                        )
                                    )
                                )(else
                                    (if (Said('break/window'))
                                        Print(89 19)
                                    )(else
                                        (if (Said('get>'))
                                            (if (Said('/caldron'))
                                                Print(89 20)
                                            )(else
                                                (if (Said('/dish'))
                                                    (if (not (send newProp_2:cel()))
                                                        Print(89 21)
                                                    )(else
                                                        Print(89 22)
                                                    )
                                                )(else
                                                    (if (Said('/all,possessions,inventory'))
                                                        (if (not local7)
                                                            Print(89 2)
                                                        )(else
                                                            (if (not (send newProp:cel()))
                                                                Print(89 21)
                                                            )(else
                                                                (if (> (send gEgo:distanceTo(newProp)) 25)
                                                                    Print(800 1)
                                                                )(else
                                                                    = local6 1
                                                                    = gInvFirst (send gInv:first())
                                                                    (while (gInvFirst)
                                                                        (if ((= local5 NodeValue(gInvFirst)) and (== (send ((= local5 NodeValue(gInvFirst))):owner()) 89))
                                                                            (send local5:owner(gEgo))
                                                                            = local6 0
                                                                        )
                                                                        = gInvFirst (send gInv:next(gInvFirst))
                                                                    )
                                                                    (if (not local6)
                                                                        (send gGame:changeScore(4))
                                                                        (send newView:
                                                                            loop(2)
                                                                            cel(2)
                                                                            startUpd()
                                                                            forceUpd()
                                                                        )
                                                                        = global182 1
                                                                        = local7 0
                                                                    )(else
                                                                        Print(89 2)
                                                                    )
                                                                    (send newView:stopUpd())
                                                                )
                                                            )
                                                        )
                                                    )(else
                                                        (if ((local7 and (< (send gEgo:distanceTo(newProp)) 25)) and (<> (send newProp:cel()) (- NumCels(newProp) 1)))
                                                            Print(89 23)
                                                            (send pEvent:claimed(1))
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )

)
(instance rightCabinet of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send newProp:stopUpd()) = state -1 )
            )
        )
    )

)
(instance leftCabinet of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send newProp_2:stopUpd()) = state -1 )
            )
        )
    )

)
