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


(local
    newView
    newAct

)
(instance chickenMusic of Sound
    (properties)
)
(instance public Room84 of Rm
    (properties
        picture 84
        style 16
    )

    (method (init)
        (self:setRegions(604))
        Load(rsVIEW 360)
        Load(rsVIEW 519)
        Load(rsVIEW 649)
        Load(rsVIEW 634)
        Load(rsVIEW 512)
        Load(rsVIEW 40)
        Load(rsSOUND 79)
        (super:init())
        (send ((View:new())):
            view(634)
            loop(1)
            cel(0)
            posn(31 78)
            setPri(4)
            init()
            addToPic()
        )
        (send ((View:new())):
            view(634)
            loop(1)
            cel(0)
            posn(71 79)
            setPri(4)
            init()
            addToPic()
        )
        (if (global100)
            (send ((View:new())):
                view(649)
                loop(1)
                posn(102 67)
                setPri(3)
                init()
                addToPic()
            )
            (send ((View:new())):
                view(649)
                loop(1)
                posn(138 67)
                setPri(3)
                init()
                addToPic()
            )
            (send ((View:new())):
                view(649)
                loop(1)
                posn(177 67)
                setPri(3)
                init()
                addToPic()
            )
            (send ((View:new())):
                view(649)
                loop(1)
                posn(215 67)
                setPri(3)
                init()
                addToPic()
            )
            (send ((Prop:new())):
                view(512)
                loop(0)
                posn(33 66)
                setPri(3)
                init()
                setCycle(Fwd)
            )
            (send ((Prop:new())):
                view(512)
                loop(0)
                posn(73 67)
                setPri(3)
                init()
                setCycle(Fwd)
            )
        )
        (if (== (send ((send gInv:at(4))):owner()) 84)
            (send (= newView (View:new())):
                view(519)
                ignoreActors(0)
                posn(200 136)
                init()
            )
        )
        (if (== (send ((send gInv:at(33))):owner()) 84)
            (send (= newAct (Act:new())):
                view(360)
                illegalBits(0)
                posn(80 134)
                init()
                setScript(henPacing)
            )
            (chickenMusic:
                number(79)
                loop(-1)
                play()
            )
        )
        (if ((== gPicture 87) or (== gPicture 0))
            (send gEgo:
                posn(157 163)
                view(4)
                xStep(4)
                yStep(1)
                init()
            )
            (if (global175)
                = global175 0
            )
        )
    )


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


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


    (method (handleEvent pEvent)
        (var temp0[80])
        return 
            (if ((send pEvent:claimed()))
                return 1
            )(else
                (if (== (send pEvent:type()) 128)
                    (if (Said('look[<around][/!*]') or Said('look/room'))
                        Print(84 0)
                        (if ((== (send ((send gInv:at(4))):owner()) 84) and (== (send ((send gInv:at(33))):owner()) 84))
                            Print(84 1)
                        )(else
                            (if (== (send ((send gInv:at(33))):owner()) 84)
                                Print(84 2)
                            )(else
                                (if (== (send ((send gInv:at(4))):owner()) 84)
                                    Print(84 3)
                                )(else
                                    Print(84 4)
                                )
                            )
                        )
                    )(else
                        (if (Said('look>'))
                            (if (Said('/box'))
                                Print(84 5)
                            )(else
                                (if (Said('/barrel'))
                                    Print(84 6)
                                )(else
                                    (if (Said('/chest'))
                                        Print(84 7)
                                    )(else
                                        (if (Said('/shelf'))
                                            Print(84 8)
                                        )(else
                                            (if (Said('/['))
                                                Print(84 9)
                                            )(else
                                                (if (Said('/window'))
                                                    Print(84 10)
                                                )(else
                                                    (if (Said('/wall'))
                                                        Print(84 11)
                                                    )(else
                                                        (if (Said('/dirt') or Said('<down'))
                                                            Print(84 12)
                                                        )(else
                                                            (if (Said('/chicken'))
                                                                (if (== (send ((send gInv:at(33))):owner()) 84)
                                                                    Print(84 13)
                                                                )(else
                                                                    Print(84 14 134 -1 20)
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )(else
                            (if (Said('get>'))
                                (if (Said('/box<pandora'))
                                    (if ((send gEgo:has(4)))
                                        Print(800 0)
                                    )(else
                                        (if (<> (send ((send gInv:at(4))):owner()) 84)
                                            Print(84 15)
                                        )(else
                                            (if (< (send gEgo:distanceTo(newView)) 20)
                                                (send gEgo:get(4))
                                                (send gGame:changeScore(2))
                                                (egoPickUp:changeState(0))
                                                (send newView:dispose())
                                            )(else
                                                Print(800 1)
                                            )
                                        )
                                    )
                                )(else
                                    (if (Said('/chicken'))
                                        (if ((send gEgo:has(33)))
                                            Print(84 16)
                                        )(else
                                            (if (<> (send ((send gInv:at(33))):owner()) 84)
                                                Print(84 15)
                                            )(else
                                                (if (< (send gEgo:distanceTo(newAct)) 20)
                                                    (chickenMusic:dispose())
                                                    (send gEgo:get(33))
                                                    (send gGame:changeScore(2))
                                                    (egoPickUp:changeState(0))
                                                    (send newAct:dispose())
                                                )(else
                                                    Print(800 1)
                                                )
                                            )
                                        )
                                    )(else
                                        (if (Said('/box'))
                                            Print(84 5)
                                        )(else
                                            (if (Said('/chest'))
                                                Print(84 7)
                                            )(else
                                                (if (Said('open/window'))
                                                    Print(84 17)
                                                )(else
                                                    (if (Said('break/window'))
                                                        Print(84 18)
                                                    )(else
                                                        (if (Said('/['))
                                                            Print(84 9)
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )(else
                                (if (Said('open>'))
                                    (if (Said('/box<pandora'))
                                        (send pEvent:claimed(0))
                                    )(else
                                        (if (Said('/box'))
                                            Print(84 5)
                                        )(else
                                            (if (Said('/barrel'))
                                                Print(84 6)
                                            )(else
                                                (if (Said('/chest'))
                                                    Print(84 7)
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )

)
(instance egoPickUp of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= global182 1 (User:
                    canControl(0)
                    canInput(0)
                )
 (send gEgo:
                    view(40)
                    cel(0)
                    setMotion(0)
                    setCycle(End self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    view(4)
                    setCycle(Walk)
                )
 (User:
                    canControl(1)
                    canInput(1)
                )
 )
            )
        )
    )

)
(instance henPacing of Script
    (properties)

    (method (init param1)
        (super:init(param1))
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (
                (if ((send gCast:contains(newAct)))
                    (send newAct:
                        loop(+ (send newAct:loop()) 2)
                        setCycle(End self)
                    )
                )
 )
            )
            (case 1
                (
                (if ((send gCast:contains(newAct)))
                    (send newAct:
                        setCycle(Walk)
                        setMotion(MoveTo 
                            (if (> (send newAct:x()) 87)
                                Random(67 85)
                            )(else
                                Random(90 120)
                            )
 134 self)
                    )
                )
 )
            )
            (case 2
                (= state -1 (self:cue()) )
            )
        )
    )

)
