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


(local
    local0
    newAct
    newAct_2
    newProp_3
    newAct_3
    newProp
    newProp_2
    local7
    local8
    local9
    gInvFirst

)
(instance theMusic of Sound
    (properties)
)
(instance public Room81 of Rm
    (properties
        picture 81
        style 16
    )

    (method (init)
        Load(rsVIEW 141)
        Load(rsVIEW 604)
        Load(rsVIEW 633)
        Load(rsVIEW 646)
        (super:init())
        (self:setRegions(604))
        (send ((View:new())):
            view(633)
            loop(2)
            cel(0)
            posn(122 71)
            setPri(3)
            addToPic()
        )
        (send ((View:new())):
            view(633)
            loop(2)
            cel(0)
            posn(196 72)
            setPri(3)
            addToPic()
        )
        (if (global100)
            (send (= newProp (Prop:new())):
                view(646)
                loop(1)
                cel(0)
                posn(225 95)
                init()
                stopUpd()
            )
            (send (= newProp_2 (Prop:new())):
                view(646)
                loop(0)
                cel(0)
                posn(91 92)
                init()
                stopUpd()
            )
            (send ((View:new())):
                view(633)
                loop(0)
                cel(3)
                posn(20 180)
                setPri(14)
                addToPic()
            )
            (send ((Prop:new())):
                view(633)
                loop(0)
                cel(4)
                posn(122 61)
                setPri(2)
                init()
                setCycle(Fwd)
            )
            (send ((Prop:new())):
                view(633)
                loop(1)
                cel(3)
                posn(197 62)
                setPri(2)
                init()
                setCycle(Fwd)
            )
        )
        = local7 0
        = local8 0
        (theMusic:
            number(43)
            loop(0)
            init()
        )
        (send (= newProp_3 (Prop:new())):
            view(604)
            posn(83 154)
            cel(0)
            ignoreActors()
            setPri(12)
            init()
            stopUpd()
        )
        (if ((== gPicture 85) or (== gPicture 0))
            (send gEgo:
                posn(68 164)
                view(4)
                setStep(4 1)
                illegalBits(49152)
                init()
            )
        )
        (if ((== gPicture 92) and not global175)
            (User:
                canControl(0)
                canInput(0)
            )
            (send gEgo:
                posn(83 166)
                view(4)
                xStep(4)
                yStep(1)
                setPri(-1)
                illegalBits(0)
                ignoreActors(1)
                init()
                setCycle(Walk)
                setMotion(0)
            )
            (send (= newAct (Act:new())):
                view(141)
                posn(98 176)
                setStep(4 1)
                ignoreActors(1)
                init()
                setCycle(Walk)
            )
            (send (= newAct_2 (Act:new())):
                view(141)
                posn(115 182)
                setStep(4 1)
                ignoreActors(1)
                init()
                setCycle(Walk)
            )
            (send newProp_3:cel(4))
            (self:setScript(lockUp))
        )
        (if (global175)
            = global175 0
            (User:
                canControl(0)
                canInput(0)
            )
            (send gEgo:
                posn(83 166)
                view(4)
                illegalBits(49152)
                setStep(4 1)
                setPri(-1)
                init()
                setCycle(Walk)
            )
            (send (= newAct (Act:new())):
                view(141)
                posn(115 182)
                setStep(4 1)
                ignoreActors(1)
                illegalBits(0)
                init()
                setCycle(Walk)
            )
            (send newProp_3:cel(4))
            (self:setScript(lockUpLast))
        )
        = global205 0
    )


    (method (doit)
        (super:doit())
        (if (& (send gEgo:onControl(0)) $0040)
            (send global2:newRoom(85))
        )
        (if ((< (send gEgo:distanceTo(newProp_3)) 25) and (send ((send gInv:at(34))):ownedBy(81)))
            Print(81 0 66 global23 164 409 0 0 134 -1 20)
            = global182 1
            (send gEgo:get(34))
        )
    )


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


    (method (handleEvent pEvent)
        return 
            (if ((send pEvent:claimed()))
                return 1
            )(else
                (if (== (send pEvent:type()) 128)
                    (if (not & (send gEgo:onControl(0)) $0800)
                        (if (Said('look[<around][/!*]') or Said('look/castle,tower,room,bedroom'))
                            Print(81 1)
                        )(else
                            (if (Said('look>'))
                                (if (Said('<under/bed'))
                                    Print(81 2)
                                )(else
                                    (if (Said('/bed'))
                                        Print(81 3)
                                    )(else
                                        (if (Said('/window'))
                                            (if ((send gEgo:inRect(201 117 238 126)) or (send gEgo:inRect(79 113 116 123)))
                                                Print(81 4)
                                            )(else
                                                Print(800 1)
                                            )
                                        )(else
                                            (if (Said('<in/chest,dresser') or Said('<in/drawer[<chest]'))
                                                Print(81 5)
                                            )(else
                                                (if (Said('/chest,dresser'))
                                                    Print(81 6)
                                                )(else
                                                    (if (Said('/dirt') or Said('<down'))
                                                        (if (== (send ((send gInv:at(34))):owner()) 81)
                                                            Print(81 7)
                                                        )(else
                                                            Print(81 8)
                                                        )
                                                    )(else
                                                        (if (Said('/mirror'))
                                                            (if ((send gEgo:inRect(218 135 272 154)))
                                                                Print(81 9)
                                                            )(else
                                                                Print(800 1)
                                                            )
                                                        )(else
                                                            (if (Said('/carpet'))
                                                                Print(81 10)
                                                            )(else
                                                                (if (Said('/stair'))
                                                                    Print(81 11)
                                                                )(else
                                                                    (if (Said('/door'))
                                                                        Print(81 12)
                                                                    )(else
                                                                        (if (Said('/key'))
                                                                            (if ((send gEgo:has(34)) and not (send gEgo:has(32)))
                                                                                Print(81 13)
                                                                            )(else
                                                                                (send pEvent:claimed(0))
                                                                            )
                                                                        )
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )(else
                                (if ((send ((send gInv:at(34))):ownedBy(81)) and Said('get/rose'))
                                    proc0_15()
                                )(else
                                    (if ((Said('lay,sleep,get/bed') or Said('sleep')) or Said('lay<down,sleep'))
                                        Print(81 14)
                                    )(else
                                        (if (Said('open/chest') or Said('open/drawer[<chest]'))
                                            Print(81 5)
                                        )(else
                                            (if (Said('open/window'))
                                                Print(81 15)
                                            )(else
                                                (if (Said('break/window'))
                                                    Print(81 16)
                                                )(else
                                                    (if (Said('[use]/key<skeleton'))
                                                        (if (not (send gEgo:has(20)))
                                                            proc0_19()
                                                        )(else
                                                            (if (not local8)
                                                                Print(81 17)
                                                            )(else
                                                                Print(81 18)
                                                            )
                                                        )
                                                    )(else
                                                        (if (Said('unlatch/door'))
                                                            (if (not local8)
                                                                Print(81 19)
                                                            )(else
                                                                (if (> (send gEgo:distanceTo(newProp_3)) 15)
                                                                    Print(800 1)
                                                                )(else
                                                                    (if ((send gEgo:has(32)))
                                                                        = local8 0
                                                                        Print(81 20)
                                                                        (send gGame:changeScore(2))
                                                                    )(else
                                                                        Print(81 21)
                                                                    )
                                                                )
                                                            )
                                                        )(else
                                                            (if (Said('[use]/key<gold') or Said('gold'))
                                                                (if (> (send gEgo:distanceTo(newProp_3)) 15)
                                                                    Print(800 1)
                                                                )(else
                                                                    (if (not (send gEgo:has(32)))
                                                                        Print(800 2)
                                                                    )(else
                                                                        (if (not local8)
                                                                            Print(81 22)
                                                                        )(else
                                                                            (if (local7 or not (send gEgo:has(20)))
                                                                                Print(81 20)
                                                                                = local8 0
                                                                                (send gGame:changeScore(2))
                                                                            )(else
                                                                                Print(81 23)
                                                                            )
                                                                        )
                                                                    )
                                                                )
                                                            )(else
                                                                (if (Said('open/door'))
                                                                    (if (> (send gEgo:distanceTo(newProp_3)) 15)
                                                                        Print(800 1)
                                                                    )(else
                                                                        (if (local8)
                                                                            Print(81 24)
                                                                        )(else
                                                                            (if (== (send newProp_3:cel()) 0)
                                                                                (send newProp_3:
                                                                                    startUpd()
                                                                                    setCycle(End doDoor)
                                                                                )
                                                                                (User:
                                                                                    canControl(0)
                                                                                    canInput(0)
                                                                                )
                                                                                (send gEgo:
                                                                                    posn((send gEgo:x()) 146)
                                                                                    illegalBits(32768)
                                                                                )
                                                                                (send ((Sound:new())):
                                                                                    number(300)
                                                                                    loop(1)
                                                                                    play()
                                                                                )
                                                                            )(else
                                                                                Print(81 25)
                                                                            )
                                                                        )
                                                                    )
                                                                )(else
                                                                    (if (Said('close/door'))
                                                                        (if (== (send newProp_3:cel()) 0)
                                                                            Print(81 19)
                                                                        )(else
                                                                            Print(81 26)
                                                                        )
                                                                    )(else
                                                                        (if (Said('get,untie,detach/key'))
                                                                            (if ((send gEgo:has(34)) and not (send gEgo:has(32)))
                                                                                Print(81 27)
                                                                                = global182 1
                                                                                (send gEgo:get(32))
                                                                                (send gGame:changeScore(2))
                                                                                (send ((send gInv:at(34))):
                                                                                    description("What a beautiful red rose!")
                                                                                    loop(1)
                                                                                    cel(0)
                                                                                )
                                                                            )(else
                                                                                (send pEvent:claimed(0))
                                                                            )
                                                                        )
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )(else
                        (if (Said('look[<around][/!*]') or Said('look/room'))
                            Print(81 28)
                        )(else
                            (if (Said('look/stair'))
                                Print(81 29)
                            )(else
                                (if (Said('look/door'))
                                    Print(81 12)
                                )(else
                                    (if (Said('look/wall'))
                                        Print(81 30)
                                    )(else
                                        (if (Said('close/door'))
                                            Print(81 26)
                                        )(else
                                            (if (Said('open/door'))
                                                (if (> (send gEgo:distanceTo(newProp_3)) 15)
                                                    Print(800 1)
                                                )(else
                                                    (if (== (send newProp_3:cel()) 0)
                                                        (send newProp_3:
                                                            startUpd()
                                                            setCycle(End doDoor)
                                                        )
                                                        (User:
                                                            canControl(0)
                                                            canInput(0)
                                                        )
                                                        (send gEgo:
                                                            illegalBits(32768)
                                                            setMotion(0)
                                                        )
                                                        (send ((Sound:new())):
                                                            number(300)
                                                            loop(1)
                                                            play()
                                                        )
                                                    )(else
                                                        Print(81 31)
                                                    )
                                                )
                                            )(else
                                                (if (Said('unlatch/*'))
                                                    Print(81 32)
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )

)
(instance doDoor of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send newProp_3:stopUpd()) (User:
                    canControl(1)
                    canInput(1)
                )
 )
            )
        )
    )

)
(instance lockUp of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gEgo:
                    setMotion(0)
                    setLoop(-1)
                    setMotion(MoveTo 68 165 self)
                )
 (send newAct:setMotion(Follow gEgo 10)) (send newAct_2:setMotion(Follow gEgo 25))  )
            )
            (case 1
                ((send newAct:setMotion(0)) (send newAct_2:setMotion(0)) (send gEgo:setMotion(MoveTo 70 150 self))  )
            )
            (case 2
                ((send gEgo:setMotion(MoveTo 106 139 self)) = local8 1 (send newProp_3:setCycle(Beg))  )
            )
            (case 3
                ((send gEgo:illegalBits(49152)) (send newAct_2:
                    illegalBits(0)
                    setMotion(MoveTo 145 235 self)
                )
 (send newAct:
                    illegalBits(0)
                    setMotion(MoveTo 145 239)
                )
  )
            )
            (case 4
                ((User:
                    canControl(1)
                    canInput(1)
                )
 (send newProp_3:stopUpd()) (send newAct:dispose()) (send newAct_2:dispose()) (send (ScriptID(0 4)):setReal(self 2))  )
            )
            (case 5
                (Print(81 33 134 -1 40 50 5) (send (ScriptID(0 4)):setReal(self 30))  )
            )
            (case 6
                ((theMusic:
                    loop(1)
                    play()
                )
 (send (= newAct_3 (Act:new())):
                    view(131)
                    loop(1)
                    posn(158 216)
                    illegalBits(0)
                    init()
                    setCycle(Walk)
                    setMotion(MoveTo 68 162 self)
                )
  )
            )
            (case 7
                (= local0 Print(81 34 134 -1 35 172) (send newAct_3:
                    cycleSpeed(7)
                    setLoop(0)
                    setCycle(CT 12 1)
                )
 (send (ScriptID(0 4)):setReal(self 3))  )
            )
            (case 8
                ((send newAct_3:
                    cel(12)
                    setCycle(End self)
                )
  )
            )
            (case 9
                (proc0_23() (send ((send gInv:at(34))):moveTo(81)) (send newAct_3:
                    view(130)
                    setLoop(-1)
                    illegalBits(0)
                    setCycle(Walk)
                    cycleSpeed(0)
                    setMotion(MoveTo 190 249 self)
                )
  )
            )
            (case 10
                ((send newAct_3:dispose()) (theMusic:dispose()) = seconds 120  )
            )
            (case 11
                (proc0_10() (send gEgo:loop(0)) 
                (if (global100)
                    (send newProp:
                        cycleSpeed(7)
                        cel(0)
                        setCycle(End self)
                    )
                    (send newProp_2:
                        cycleSpeed(7)
                        cel(0)
                        setCycle(End)
                    )
                )
 )
            )
            (case 12
                (Print(81 35 134 -1 20 140 260) = seconds 12  )
            )
            (case 13
                (proc0_11() (send (ScriptID(604)):keep(0)) (send global2:newRoom(692)) )
            )
        )
    )

)
(instance lockUpLast of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = gInvFirst (send gInv:first()) (while (gInvFirst)
                    (if ((= local9 NodeValue(gInvFirst)) and (== (send ((= local9 NodeValue(gInvFirst))):owner()) gEgo))
                        (send local9:owner(89))
                    )
 = gInvFirst (send gInv:next(gInvFirst))  ) (send gEgo:
                    setMotion(0)
                    illegalBits(0)
                )
 (send newAct:setMotion(Follow gEgo 10)) (send gEgo:
                    setLoop(-1)
                    setMotion(MoveTo 68 165 self)
                )
  )
            )
            (case 1
                ((send newAct:setMotion(0)) (send gEgo:setMotion(MoveTo 70 150 self))  )
            )
            (case 2
                ((send gEgo:setMotion(MoveTo 106 139 self)) = local8 1 (send newProp_3:setCycle(Beg))  )
            )
            (case 3
                ((send newAct:
                    ignoreActors(1)
                    setMotion(MoveTo 150 225 self)
                )
  )
            )
            (case 4
                ((send gEgo:setMotion(MoveTo 182 147 self)) (send newProp_3:stopUpd()) (send newAct:dispose())  )
            )
            (case 5
                ((send gEgo:setMotion(MoveTo 216 124 self))  )
            )
            (case 6
                ((send gEgo:loop(0)) 
                (if (global100)
                    (send newProp:
                        cycleSpeed(7)
                        cel(0)
                        setCycle(End self)
                    )
                    (send newProp_2:
                        cycleSpeed(7)
                        cel(0)
                        setCycle(End)
                    )
                )
 )
            )
            (case 7
                (Print(81 36 134 -1 20 140 260 50 10) (send gEgo:setMotion(MoveTo 160 149 self))  )
            )
            (case 8
                ((send gEgo:loop(2)) = seconds 3  )
            )
            (case 9
                (proc0_11() (send global2:newRoom(692)) (send (ScriptID(604)):keep(0)) = global189 0 )
            )
        )
    )

)
