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


(local
    newAct
    local1
    newProp_3
    local3
    newView
    newProp
    newProp_2

)
(instance public Room58 of Rm
    (properties
        picture 58
        style 16
    )

    (method (init)
        Load(rsVIEW 58)
        Load(rsVIEW 42)
        Load(rsVIEW 44)
        Load(rsVIEW 521)
        Load(rsSOUND 51)
        Load(rsSOUND 52)
        Load(rsPIC 66)
        Load(rsPIC 61)
        (super:init())
        (self:setRegions(603))
        (theMusic:
            number(57)
            loop(0)
        )
        (if ((send ((send gInv:at(20))):ownedBy(gGNewPropX)))
            = local3 1
        )
        (if (global193)
            = local1 1
        )(else
            = local1 0
        )
        (send ((View:new())):
            view(521)
            loop(2)
            cel(0)
            posn(102 75)
            setPri(4)
            addToPic()
        )
        (send ((View:new())):
            view(521)
            loop(2)
            cel(1)
            posn(231 75)
            setPri(4)
            addToPic()
        )
        (send (= newProp (Prop:new())):
            view(521)
            loop(3)
            posn(104 59)
            setPri(2)
            init()
            setCycle(Fwd)
        )
        (send (= newProp_2 (Prop:new())):
            view(521)
            loop(3)
            posn(228 59)
            setPri(2)
            init()
            setCycle(Fwd)
        )
        (send (= newProp_3 (Prop:new())):
            view(521)
            loop(1)
            posn(181 96)
            setPri(5)
            init()
        )
        (if (global193)
            (send newProp_3:
                setCel(255)
                addToPic()
            )
        )(else
            (send newProp_3:hide())
        )
        (send gEgo:
            view(4)
            setStep(4 1)
            setPri(11)
            illegalBits(16384)
            posn(121 155)
            baseSetter(ScriptID(0 1))
            init()
        )
    )


    (method (doit)
        (if (((& (send gEgo:onControl()) $0002) and (== (send gEgo:illegalBits()) 32768)) and not (send gEgo:script()))
            (send gEgo:
                setPri(11)
                illegalBits(16384)
                baseSetter(ScriptID(0 1))
            )
        )
        (if (((& (send gEgo:onControl()) $0010) and not (& (send gEgo:onControl(1)) $0002)) and not (send gEgo:script()))
            (send gEgo:
                setPri(-1)
                illegalBits(32768)
                baseSetter(0)
            )
        )
        (if ((& (send gEgo:onControl(0)) $0040) and (<> (send gEgo:script()) fallHole))
            (send global2:newRoom(61))
        )
        (if (((& (send gEgo:onControl()) $0004) and (<> (send gEgo:illegalBits()) 16384)) and (<> (send gEgo:script()) fallHole))
            proc0_10()
            (send gEgo:setScript(fallHole))
        )
        (super:doit())
    )


    (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 (Said('look[<around][/!*]') or Said('look/room,tower'))
                        Print(58 0)
                    )(else
                        (if (Said('look>'))
                            (if (Said('<down') or Said('/stair'))
                                Print(58 1)
                            )(else
                                (if (Said('<behind/organ'))
                                    Print(58 2)
                                )(else
                                    (if (Said('<in/organ'))
                                        Print(58 3)
                                    )(else
                                        (if (Said('/organ'))
                                            Print(58 4)
                                        )(else
                                            (if (Said('/bench'))
                                                Print(58 5)
                                            )(else
                                                (if (Said('/wall'))
                                                    Print(58 6)
                                                )(else
                                                    (if (Said('/dirt') or Said('<down'))
                                                        Print(58 7)
                                                    )(else
                                                        (if (Said('/drawer'))
                                                            (if (local1)
                                                                (if (local3)
                                                                    Print(58 8)
                                                                )(else
                                                                    Print(58 9)
                                                                )
                                                            )(else
                                                                Print(58 10)
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )(else
                            (if (Said('move/bench'))
                                Print(58 11)
                            )(else
                                (if (Said('play,use/music<sheet'))
                                    (if (== (send gEgo:view()) 58)
                                        (if ((send gEgo:has(26)))
                                            Print(58 12)
                                            (playOrgan:changeState(10))
                                        )(else
                                            Print(58 13)
                                        )
                                    )(else
                                        (if ((send gEgo:has(26)))
                                            Print(58 14)
                                        )(else
                                            Print(58 13)
                                        )
                                    )
                                )(else
                                    (if (Said('play,use/organ,music') or Said('play[/!*]'))
                                        (if (== (send gEgo:view()) 58)
                                            (if ((send gEgo:has(26)))
                                                Print(58 15)
                                            )
                                            (playOrgan:changeState(0))
                                        )(else
                                            Print(58 16)
                                        )
                                    )(else
                                        (if (Said('sit') or Said('sit/organ,bench'))
                                            (if (== (send gEgo:view()) 58)
                                                Print(58 17)
                                            )(else
                                                (if ((send gEgo:inRect(129 121 195 126)))
                                                    (self:setScript(sitOrgan))
                                                )(else
                                                    (if ((send gEgo:inRect(122 126 211 137)))
                                                        Print(58 18)
                                                    )(else
                                                        Print(800 1)
                                                    )
                                                )
                                            )
                                        )(else
                                            (if ((Said('get<up') or Said('stand[<up]')) or Said('(/organ,bench'))
                                                (if (== (send gEgo:view()) 58)
                                                    (self:setScript(standOrgan))
                                                )(else
                                                    Print(58 19)
                                                )
                                            )(else
                                                (if (Said('get/key'))
                                                    (if (local1)
                                                        (if (local3)
                                                            Print(58 20)
                                                            = local3 0
                                                            = global182 1
                                                            (send gEgo:get(20))
                                                            (send gGame:changeScore(2))
                                                        )(else
                                                            proc0_16()
                                                        )
                                                    )(else
                                                        Print(58 21)
                                                    )
                                                )(else
                                                    (if (Said('close/drawer'))
                                                        (if (local1)
                                                            Print(58 22)
                                                        )(else
                                                            Print(58 23)
                                                        )
                                                    )(else
                                                        (if (Said('open/drawer'))
                                                            (if (local1)
                                                                Print(58 24)
                                                            )(else
                                                                Print(58 23)
                                                            )
                                                        )(else
                                                            (if (Said('open/bench'))
                                                                Print(58 25)
                                                            )(else
                                                                (if (Said('find/drawer'))
                                                                    (if (local1)
                                                                        Print(58 26)
                                                                    )(else
                                                                        Print(58 27)
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )

)
(instance playOrgan of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((User:canInput(0)) (send newAct:
                    loop(2)
                    setCycle(Fwd)
                )
 (theMusic:
                    number(56)
                    loop(1)
                    play(self)
                )
  )
            )
            (case 1
                (Print(58 28) (send newAct:
                    cel(0)
                    loop(4)
                    setCycle(0)
                )
 (User:canInput(1)) (theMusic:loop(0))  )
            )
            (case 10
                (proc0_10() (send (= newView (View:new())):
                    view(521)
                    loop(0)
                    cel(0)
                    posn(162 95)
                    setPri(6)
                    init()
                )
 (send newAct:
                    loop(2)
                    setCycle(Fwd)
                )
 (theMusic:
                    number(57)
                    loop(1)
                    play(self)
                )
  )
            )
            (case 11
                (
                (if (== global193 0)
                    ++global193
                    Print(58 29)
                    (send gGame:changeScore(4))
                    (send newProp_3:
                        show()
                        setCycle(End)
                    )
                    = local1 1
                )(else
                    (theMusic:loop(0))
                    (send newView:dispose())
                )
 (send newAct:
                    cel(0)
                    loop(4)
                    setCycle(0)
                )
 (send newView:dispose()) (User:canInput(1)) )
            )
        )
    )

)
(instance theMusic of Sound
    (properties)
)
(instance sitOrgan of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((User:canControl(0)) (send gEgo:setMotion(MoveTo 164 125 self))  )
            )
            (case 1
                ((send gEgo:loop(2)) (self:cue())  )
            )
            (case 2
                ((send (= newAct (Act:new())):
                    view(58)
                    loop(0)
                    cel(0)
                    setPri(9)
                    posn((send gEgo:x()) - (send gEgo:y()) 13)
                    ignoreActors(1)
                    illegalBits(0)
                    init()
                )
 (send gEgo:
                    view(58)
                    loop(1)
                    cel(0)
                )
 (send gEgo:setCycle(End)) (send newAct:setCycle(End self))  )
            )
            (case 3
                ((send client:setScript(0)) )
            )
        )
    )

)
(instance standOrgan of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() (send gEgo:
                    cel(0)
                    loop(5)
                    setCycle(End)
                )
 (send newAct:
                    cel(0)
                    loop(4)
                    setCycle(End self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    setPri(-1)
                    view(4)
                    loop(3)
                    setCycle(Walk)
                )
 (send newAct:dispose()) proc0_11() (send client:setScript(0)) )
            )
        )
    )

)
(instance fallHole of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((theMusic:
                    number(51)
                    loop(1)
                    play(self)
                )
 (send gEgo:setMotion(0)) proc0_10() (send gEgo:
                    view(44)
                    setStep(-1 10)
                    setCycle(Fwd)
                    setPri(
                        (if (< (send gEgo:priority()) 11)
                            (send gEgo:priority())
                        )(else
                            11
                        )
)
                    illegalBits(0)
                    setMotion(MoveTo 160 252)
                )
  )
            )
            (case 1
                ((send gCast:eachElementDo(256)) 
                (if ((send gSounds:contains(theMusic)))
                    (theMusic:dispose())
                )
 (send gEgo:hide()) (send global2:drawPic(61 6)) (theMusic:
                    number(52)
                    loop(1)
                    play()
                )
 (send gEgo:
                    setStep(-1 10)
                    setCycle(Fwd)
                    illegalBits(0)
                    posn(160 10)
                    setPri(14)
                    show()
                    setLoop((send gEgo:loop()))
                    setMotion(MoveTo 160 150 self)
                )
  )
            )
            (case 2
                ((send gEgo:
                    setPri(14)
                    setMotion(MoveTo 160 256 self)
                )
  )
            )
            (case 3
                (
                (if ((send gSounds:contains(theMusic)))
                    (theMusic:dispose())
                )
 (send gEgo:hide()) (send global2:drawPic(66 6)) (theMusic:
                    number(52)
                    loop(1)
                    play()
                )
 (send gEgo:
                    posn(160 10)
                    show()
                    setPri(-1)
                    setMotion(MoveTo 212 136 self)
                )
  )
            )
            (case 4
                ((send gSounds:eachElementDo(172)) (send gEgo:view(42)) proc0_20() kernel[106](10) = seconds 3  )
            )
            (case 5
                (= global127 1 )
            )
        )
    )

)
