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


(local
    gEgoOnControl
    theGEgoOnControl
    newAct
    local3
    local4
    newProp_5
    gEgoViewer
    newProp
    local8
    newProp_2
    newProp_3
    newProp_4

)
(instance public Room23 of Rm
    (properties
        picture 23
        north 17
        east 24
        south 29
        west 22
    )

    (method (init)
        = north 17
        = south 29
        = east 24
        = west 22
        = horizon 74
        = global101 0
        (send gEgo:edgeHit(0))
        (if (global100)
            = picture 123
        )
        (super:init())
        (self:setRegions(508 501 512))
        Load(rsVIEW 17)
        Load(rsVIEW 18)
        Load(rsVIEW 21)
        Load(rsVIEW 21)
        Load(rsVIEW 348)
        Load(rsSOUND 51)
        Load(rsSOUND 80)
        = newProp (Prop:new())
        (send newProp:
            view(654)
            loop(0)
            cel(0)
            posn(146 154)
            setPri(0)
            setCycle(Fwd)
            ignoreActors()
            init()
        )
        = newProp_2 (Prop:new())
        = newProp_3 (Prop:new())
        = newProp_4 (Prop:new())
        (send newProp_2:
            isExtra(1)
            view(654)
            loop(2)
            cel(1)
            posn(75 157)
            setPri(0)
            setCycle(Fwd)
            ignoreActors()
            init()
        )
        (send newProp_3:
            isExtra(1)
            view(654)
            loop(3)
            cel(2)
            posn(101 165)
            setPri(0)
            setCycle(Fwd)
            ignoreActors()
            init()
        )
        (send newProp_4:
            isExtra(1)
            view(654)
            loop(4)
            cel(2)
            posn(224 116)
            setPri(0)
            setCycle(Fwd)
            ignoreActors()
            init()
        )
        (switch (gPicture)
            (case west
                ((send gEgo:posn(1 (send gEgo:y())))  )
            )
            (case east
                ((send gEgo:x(318)) 
                (if (<= (send gEgo:y()) 109)
                    (send gEgo:y(100))
                )
 )
            )
            (case north
                ((send gEgo:posn(120 (+ horizon 1)))  )
            )
            (case south
                ((send gEgo:
                    x(106)
                    y(188)
                )
  )
            )
            (case 0
                ((send gEgo:
                    x(180)
                    y(188)
                )
 )
            )
        )
        = gEgoViewer (send gEgo:viewer())
        (if ((<= Random(1 100) 50) and (send ((Inv:at(19))):ownedBy(206)))
            = newAct (Act:new())
            (send newAct:
                view(348)
                loop(2)
                cel(0)
                setScript(birdActions)
                posn(275 159)
                setCycle(Fwd)
                illegalBits(0)
                ignoreActors()
                ignoreHorizon()
                init()
            )
            (send gEgo:setScript(wormActions))
        )
        (send gEgo:init())
    )


    (method (doit)
        (super:doit())
        (if ((<> (= gEgoOnControl (send gEgo:onControl())) theGEgoOnControl) and (== (send global2:script()) 0))
            = theGEgoOnControl gEgoOnControl
            (send gEgo:viewer(gEgoViewer))
            (if (& gEgoOnControl $0004)
                (self:setScript(fallSouth))
            )
            (if (& gEgoOnControl $1000)
                (self:setScript(shortFall))
            )
        )
    )


    (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(23 0)
                )(else
                    (if (Said('look/cottage'))
                        Print(23 1)
                    )(else
                        (if (Said('capture,get/earthworm'))
                            (if ((send gCast:contains(newProp_5)))
                                (if (< (send gEgo:distanceTo(newProp_5)) 15)
                                    proc0_3(gEgo newProp_5)
                                    (wormActions:changeState(10))
                                )(else
                                    Print(800 1)
                                )
                            )(else
                                Print(23 2)
                            )
                        )(else
                            (if (Said('look/crow,crow'))
                                (send pEvent:claimed(0))
                            )(else
                                (if (Said('look/robin,bird'))
                                    (if ((send gCast:contains(newAct)))
                                        (if (== (birdActions:state()) 0)
                                            Print(23 3)
                                        )(else
                                            Print(23 4)
                                        )
                                    )(else
                                        (if ((send gCast:contains(gNewAct)))
                                            (send pEvent:claimed(0))
                                        )(else
                                            Print(23 5)
                                        )
                                    )
                                )(else
                                    (if (Said('converse/robin,bird'))
                                        (if (== (birdActions:state()) 0)
                                            Print(23 6)
                                        )(else
                                            Print(23 7)
                                        )
                                    )(else
                                        (if (Said('kill/robin,bird'))
                                            Print(23 8)
                                        )(else
                                            (if (Said('capture,get,kiss/robin,bird'))
                                                (if ((send gCast:contains(newAct)) or (send gCast:contains(gNewAct)))
                                                    Print(23 9)
                                                )(else
                                                    Print(23 5)
                                                )
                                            )(else
                                                (if (Said('help/robin,bird'))
                                                    Print(23 10)
                                                )(else
                                                    (if (Said('deliver'))
                                                        (if ((send gCast:contains(newAct)))
                                                            Print(23 11)
                                                        )(else
                                                            Print(23 12)
                                                        )
                                                    )(else
                                                        (if (Said('look/earthworm'))
                                                            (if (((send gCast:contains(newAct)) and (send ((Inv:at(19))):ownedBy(206))) and (== (birdActions:state()) 0))
                                                                Print(23 3)
                                                            )(else
                                                                (if ((send ((Inv:at(19))):ownedBy(23)))
                                                                    Print(23 13)
                                                                )(else
                                                                    (if ((send gEgo:has(19)))
                                                                        (send ((Inv:at(19))):showSelf())
                                                                    )(else
                                                                        Print(23 5)
                                                                    )
                                                                )
                                                            )
                                                        )(else
                                                            (if (Said('look/dirt'))
                                                                (if ((send ((Inv:at(19))):ownedBy(23)))
                                                                    Print(23 13)
                                                                )(else
                                                                    (if ((== (birdActions:state()) 0) and (send gCast:contains(newAct)))
                                                                        Print(23 3)
                                                                    )(else
                                                                        Print(23 14)
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )(else
                0
            )
    )


    (method (newRoom param1)
        (send gTimers:eachElementDo(172 192))
        (if ((send ((Inv:at(19))):ownedBy(23)))
            (send ((Inv:at(19))):moveTo(206))
        )
        (super:newRoom(param1))
    )

)
(instance fallSouth of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() (send ((Sound:new())):
                    number(51)
                    loop(1)
                    play()
                )
 (send gEgo:
                    viewer(0)
                    yStep(6)
                    yStep(6)
                    illegalBits(0)
                    loop(& (send gEgo:loop()) $0001)
                    setCel(0)
                    view(17)
                    setCycle(End)
                    setMotion(MoveTo (send gEgo:x()) + (send gEgo:y()) 18 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    xStep(2)
                    yStep(1)
                    view(18)
                    loop(0)
                    setCycle(Fwd)
                )
 (send gSounds:eachElementDo(172)) (send ((Sound:new())):
                    number(80)
                    loop(1)
                    play()
                )
 = seconds 4  )
            )
            (case 2
                ((send gEgo:
                    view(21)
                    loop(2)
                    cel(4)
                    setCycle(Beg self)
                )
  )
            )
            (case 3
                (proc0_11() (send gEgo:
                    illegalBits(32768)
                    setCycle(Walk)
                    view(2)
                )
 (send global2:setScript(0)) )
            )
        )
    )

)
(instance shortFall of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() (send ((Sound:new())):
                    number(51)
                    loop(1)
                    play()
                )
 (send gEgo:
                    viewer(0)
                    view(17)
                    loop(& (send gEgo:loop()) $0001)
                    setCel(0)
                    setStep(6 6)
                    illegalBits(0)
                    setCycle(End)
                    setMotion(MoveTo (send gEgo:x()) + (send gEgo:y()) 11 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    view(18)
                    setStep(2 1)
                    loop(0)
                    setCycle(Fwd)
                )
 (send gSounds:eachElementDo(172)) (send ((Sound:new())):
                    number(80)
                    loop(1)
                    play()
                )
 = seconds 4  )
            )
            (case 2
                ((send gEgo:
                    view(21)
                    loop(2)
                    cel(4)
                    setCycle(Beg self)
                )
  )
            )
            (case 3
                ((send gEgo:
                    illegalBits(32768)
                    setCycle(Walk)
                    view(2)
                )
 proc0_11() (send global2:setScript(0)) )
            )
        )
    )

)
(instance birdActions of Script
    (properties)

    (method (doit)
        (super:doit())
        (if (((send gCast:contains(newAct)) and (< (send newAct:distanceTo(gEgo)) 30)) and (== (send newAct:loop()) 2))
            (if (local3)
                (send local3:dispose())
            )
            (self:changeState(1))
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= local3 (Timer:setReal(self 15))  )
            )
            (case 1
                ((send newAct:
                    cel(0)
                    loop(3)
                    setCycle(End self)
                )
  )
            )
            (case 2
                (= newProp_5 (Prop:new()) (send newProp_5:
                    view(348)
                    setLoop(0)
                    setCycle(Fwd)
                    ignoreActors()
                    posn(- (send newAct:x()) 8 (send newAct:y()))
                    init()
                )
 (wormActions:changeState(1)) (send newAct:
                    setPri(12)
                    setLoop(1)
                    xStep(7)
                    yStep(4)
                    setMotion(MoveTo 182 51 self)
                )
  )
            )
            (case 3
                ((send newAct:setMotion(MoveTo 20 65530 self))  )
            )
            (case 4
                ((send newAct:dispose()) = newAct 0 )
            )
        )
    )

)
(instance wormActions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 1
                (= local4 (Timer:setReal(self 12)) (send ((Inv:at(19))):moveTo(23))  )
            )
            (case 2
                ((send newProp_5:dispose()) (send ((Inv:at(19))):moveTo(206))  )
            )
            (case 10
                (proc0_10() (send local4:dispose()) (send gEgo:
                    view(21)
                    setCycle(End self)
                )
  )
            )
            (case 11
                ((send newProp_5:dispose()) = newProp_5 0 (send gEgo:setCycle(Beg self)) (send gEgo:get(19)) = global182 1 (send gGame:changeScore(2))  )
            )
            (case 12
                ((send gEgo:
                    view(2)
                    setCycle(Walk)
                )
 proc0_11() )
            )
        )
    )

)
