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


(local
    local0
    local1
    local2
    newAct
    local4
    local5
    newProp
    local7

)
(instance public Room29 of Rm
    (properties
        picture 29
    )

    (method (init)
        = north 23
        = south 5
        = east 30
        = west 28
        = horizon 100
        = global101 0
        (if (global100)
            = picture 129
        )
        (send gEgo:edgeHit(0))
        (super:init())
        (self:setRegions(508))
        Load(rsVIEW 348)
        Load(rsVIEW 17)
        Load(rsVIEW 21)
        Load(rsVIEW 348)
        Load(rsSOUND 51)
        (switch (gPicture)
            (case 28
                (
                (if (<= (send gEgo:y()) 156)
                    (send gEgo:
                        x(1)
                        y(150)
                    )
                )(else
                    (send gEgo:
                        x(1)
                        y(186)
                    )
                )
 )
            )
            (case 30
                (
                (if (<= (send gEgo:y()) horizon)
                    (send gEgo:
                        x(318)
                        y(+ horizon 1)
                    )
                )(else
                    (send gEgo:x(318))
                )
 )
            )
            (case 23
                ((send gEgo:
                    x(264)
                    y(+ horizon 2)
                )
  )
            )
            (case 5
                ((send gEgo:y(188))  )
            )
            (case 0
                ((send gEgo:
                    x(290)
                    y(160)
                )
 )
            )
        )
        (if ((<= Random(1 100) 50) and (send ((Inv:at(19))):ownedBy(206)))
            = newAct (Act:new())
            (send newAct:
                view(348)
                loop(2)
                cel(0)
                posn(257 166)
                setScript(birdActions)
                setCycle(Fwd)
                illegalBits(0)
                ignoreActors()
                ignoreHorizon()
                init()
            )
        )
        (send gEgo:
            init()
            view(2)
            setScript(wormActions)
        )
    )


    (method (doit)
        (super:doit())
        (if ((<> (= local0 (send gEgo:onControl(0))) local7) and (== (send global2:script()) 0))
            = local7 local0
            (if (& local0 $0004)
                (self:setScript(fallSouth))
            )
        )
    )


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


    (method (newRoom param1)
        (send gTimers:eachElementDo(172 192))
        (if ((send ((Inv:at(19))):ownedBy(29)))
            (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()
                )
 
                (if (> (send gEgo:x()) 100)
                    = local1 12
                )(else
                    (if (>= (send gEgo:x()) 65)
                        = local1 20
                    )(else
                        = local1 30
                    )
                )
 
                (if (> (+ (send gEgo:y()) local1) 188)
                    = local2 188
                )(else
                    = local2 (+ (send gEgo:y()) local1)
                )
 (send gEgo:
                    yStep(6)
                    yStep(6)
                    illegalBits(0)
                    loop(& (send gEgo:loop()) $0001)
                    setCel(0)
                    view(17)
                    setCycle(End)
                    setMotion(MoveTo (send gEgo:x()) local2 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    xStep(2)
                    yStep(1)
                    view(21)
                    loop(2)
                    setCycle(CT 4 1 self)
                )
  )
            )
            (case 2
                ((send gEgo:
                    view(21)
                    loop(2)
                    setCycle(Beg self)
                )
  )
            )
            (case 3
                (proc0_11() (send gEgo:
                    illegalBits(32768)
                    setCycle(Walk)
                    view(2)
                )
 (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 ((send gTimers:contains(local4)))
                (send local4:dispose())
            )
            (self:changeState(1))
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= local4 (Timer:setReal(self 15))  )
            )
            (case 1
                ((send newAct:
                    cel(0)
                    loop(3)
                    setCycle(End self)
                )
  )
            )
            (case 2
                (= newProp (Prop:new()) (send newProp:
                    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
                (= local5 (Timer:setReal(self 10)) (send ((Inv:at(19))):moveTo(29))  )
            )
            (case 2
                ((send newProp:dispose()) (send ((Inv:at(19))):moveTo(206))  )
            )
            (case 10
                ((send local5:dispose()) proc0_10() (send gEgo:
                    view(21)
                    setMotion(0)
                    setCycle(End self)
                )
  )
            )
            (case 11
                ((send newProp:dispose()) = newProp 0 (send gEgo:setCycle(Beg self)) (send gEgo:get(19)) (send gGame:changeScore(2)) = global182 1  )
            )
            (case 12
                ((send gEgo:
                    view(2)
                    setCycle(Walk)
                )
 proc0_11() )
            )
        )
    )

)
