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


(local
    newAct

)
(instance zTheme of Sound
    (properties)
)
(instance door of Prop
    (properties)

    (method (cue)
        (self:ignoreActors())
        proc0_11()
        (send global2:newRoom(68))
    )

)
(instance public Room17 of Rm
    (properties
        picture 17
    )

    (method (init)
        = north 11
        = south 23
        = east 18
        = west 16
        = horizon 100
        = global101 0
        Load(rsVIEW 610)
        (if (global100)
            = picture 117
        )
        (send gEgo:edgeHit(0))
        (self:setRegions(508))
        (super:init())
        (if (global100 and not (send gEgo:has(7)))
            Load(rsVIEW 270)
            Load(rsVIEW 36)
            Load(rsVIEW 35)
            = newAct (Act:new())
            (send newAct:
                view(270)
                cel(0)
                loop(0)
                posn(146 146)
                setPri(10)
                illegalBits(0)
                ignoreActors()
                setScript(z6Actions)
                init()
                hide()
            )
        )
        (door:
            view(610)
            loop(0)
            cel(0)
            posn(161 146)
            stopUpd()
            init()
        )
        (switch (gPicture)
            (case 16
                (
                (if (<= (send gEgo:y()) 120)
                    (send gEgo:
                        x(1)
                        y(120)
                    )
                )(else
                    (send gEgo:x(1))
                )
 )
            )
            (case 18
                (
                (if (<= (send gEgo:y()) 120)
                    (send gEgo:
                        x(318)
                        y(120)
                    )
                )(else
                    (send gEgo:x(318))
                )
 )
            )
            (case 23
                ((send gEgo:posn((send gEgo:x()) 188))  )
            )
            (case 11
                (
                (if (< (send gEgo:x()) 160)
                    (send gEgo:
                        x(42)
                        y(+ horizon (+ (send gEgo:yStep()) 1))
                    )
                )(else
                    (send gEgo:
                        x(267)
                        y(+ horizon (+ (send gEgo:yStep()) 1))
                    )
                )
 )
            )
            (case 68
                ((send gEgo:
                    loop(2)
                    x(161)
                    y(152)
                )
  )
            )
            (case 0
                ((send gEgo:
                    x(290)
                    y(160)
                )
 )
            )
        )
        (send gEgo:
            setPri(-1)
            view(2)
            xStep(2)
            yStep(1)
            init()
        )
    )


    (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/around') or Said('look/room')) or Said('look[<around][/!*]'))
                    Print(17 0)
                )(else
                    (if (Said('look>'))
                        (if (Said('/grave,gravestone,gravestone'))
                            Print(17 1)
                        )(else
                            (if (Said('/fence,wall'))
                                Print(17 2)
                            )(else
                                (if (Said('/cottage'))
                                    Print(17 3)
                                )(else
                                    (if (Said('/cemetery'))
                                        Print(17 4)
                                    )(else
                                        (if (Said('/door'))
                                            Print(17 5)
                                        )(else
                                            (if (Said('/window'))
                                                (if ((send gEgo:inRect(96 142 128 148)) or (send gEgo:inRect(194 142 229 148)))
                                                    Print(17 6)
                                                )(else
                                                    (if ((send gEgo:inRect(70 151 124 157)) or (send gEgo:inRect(193 154 260 159)))
                                                        Print(17 7)
                                                    )(else
                                                        Print(800 1)
                                                    )
                                                )
                                            )(else
                                                (if (Said('/stair'))
                                                    Print(17 8)
                                                )(else
                                                    (if (Said('look/bush') or Said('look/bush'))
                                                        Print(17 9)
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )(else
                        (if (Said('break/window'))
                            Print(17 10)
                        )(else
                            (if (Said('break/door'))
                                Print(17 11)
                            )(else
                                (if (Said('open/door'))
                                    (if ((send gEgo:inRect(139 140 173 153)))
                                        proc0_10()
                                        (send gEgo:
                                            loop(3)
                                            setPri(11)
                                        )
                                        (send ((Sound:new())):
                                            number(300)
                                            loop(1)
                                            play(door)
                                        )
                                        (door:setCycle(End))
                                    )(else
                                        Print(800 1)
                                    )
                                )(else
                                    (if (Said('close/door'))
                                        Print(17 12)
                                    )(else
                                        (if (Said('open/window'))
                                            Print(17 13)
                                        )(else
                                            (if (Said('unlatch/door'))
                                                Print(17 14)
                                            )(else
                                                (if (Said('bang/door'))
                                                    (if ((send gEgo:inRect(139 140 173 153)))
                                                        Print(17 15)
                                                    )(else
                                                        Print(800 1)
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )(else
                0
            )
    )


    (method (newRoom param1)
        (if (== (send gEgo:view()) 2)
            proc0_11()
            (send gEgo:setPri(-1))
            (super:newRoom(param1))
        )
    )

)
(instance z6Actions of Script
    (properties)

    (method (doit)
        (super:doit())
        (if ((send gEgo:inRect(141 146 175 149)) and (== state 0))
            proc0_10()
            (z6Actions:changeState(1))
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 1
                ((send newAct:
                    show()
                    setLoop(0)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 2
                ((send newAct:hide()) (zTheme:
                    number(21)
                    play(self)
                )
 (send gEgo:
                    view(35)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 3
                ((send newAct:
                    view(270)
                    show()
                    cycleSpeed(1)
                    setCycle(Beg)
                )
 (send gEgo:
                    view(36)
                    cel(0)
                    setMotion(0)
                    setCycle(End self)
                )
  )
            )
            (case 4
                ((send gEgo:
                    view(46)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 5
                ((send newAct:hide()) = global120 Print(17 16 134 -1 20 172) (send gEgo:
                    view(45)
                    x(160)
                    setCycle(Walk)
                    setMotion(MoveTo 160 230)
                )
  )
            )
            (case 6
                (= global127 1 )
            )
        )
    )

)
