(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "SQRoom")
(use "Blk")
(use "Class_950_0")
(use "n958")
(use "Sound")
(use "Cycle")
(use "PicView")
(use "Obj")
(script 290)


(local
    local0
    local1
    local2
    local3
    local4
    local5
    local6
    local7
    local8
    local9
    local10
    gGameMasterVolume
    local12
    local13
    local14[6] = (0 5 4 3 2 1 )
    local20[6] = (0 9 8 7 6 5 )
    local26 = 50

)
(instance theSound of Sound
    (properties)
)
(instance winged of Sound
    (properties
        number 56
    )
)
(instance eggSquirt of Sound
    (properties
        number 122
    )
)
(instance eggFall of Sound
    (properties
        number 131
    )
)
(instance eggSplatting of Sound
    (properties
        number 147
    )
)
(instance gunshot of Sound
    (properties
        number 144
    )
)
(instance cornPicker of Sound
    (properties
        number 146
    )
)
(instance dogBarking of Sound
    (properties
        number 827
    )
)
(instance public astro of SQRoom
    (properties)

    (method (init)
        Load(rsVIEW 290)
        Load(rsPIC 291)
        proc958_0(132 55 140 56 122 131 147 144 146)
        (self:
            drawPic(290)
            overlay(291 0)
            setScript(startScript)
        )
        (super:init())
        = picture 290
        = gGameMasterVolume (send gGame:masterVolume())
        (musicToggle:init())
        (send gSq4MouseDownHandler:add(gCast gFeatures))
        (send gIconBar:disable())
    )


    (method (doit)
        (var temp0)
        (super:doit())
        Palette(6 48 55 1)
        (if ((send global2:script))
        )(else
            (if (not --local26)
                = local26 50
                (if (not (send gCast:contains(henHouseRight)))
                    (if (not (send gCast:contains(rock)))
                        (rock:init())
                    )
                    (if (not (send gCast:contains(grass)))
                        (grass:init())
                    )
                )
            )
        )
        (if ((send global2:script))
        )(else
            (if (local3)
                (if (not --local3 and local4)
                    (send ((cornStalk:new())):init())
                    = local3 3
                    --local4
                )
            )(else
                (if ((((((>= local8 250) and not (send gCast:contains(crazedFarmer))) and not (send gCast:contains(windMill))) and not (send gCast:contains(weasel))) and not (send gCast:contains(rabidDog))) and not (send gCast:contains(astroChicken2)))
                    (henHouseLeft:init())
                    (henHouseRight:init())
                    (astroChicken2:
                        loop((astroChicken:loop))
                        x((astroChicken:x))
                        y((astroChicken:y))
                        init()
                        setCycle(Fwd)
                    )
                    (astroChicken:
                        hide()
                        dispose()
                    )
                    (send global2:setScript(doHenHouse))
                )(else
                    (if ((((((send gCast:contains(hill)) or (send gCast:contains(crazedFarmer))) or (send gCast:contains(windMill))) or (send gCast:contains(weasel))) or (send gCast:contains(chickenWire))) or (send gCast:contains(henHouseRight)))
                    )(else
                        (if ((send gSounds:contains(winged)) or (send gSounds:contains(55)))
                        )(else
                            = temp0 Random(1 100)
                            (if (<= temp0 15)
                                (hill:init())
                                (switch (Random(0 2))
                                    (case 0
                                        (if (not (send gCast:contains(rabidDog)))
                                            (rabidDog:init())
                                        )
                                    )
                                    (case 1
                                        (if (not (send gCast:contains(crazedFarmer)))
                                            (crazedFarmer:init())
                                        )
                                    )
                                )
                            )(else
                                (if (<= temp0 30)
                                    (crazedFarmer:init())
                                )(else
                                    (if (<= temp0 40)
                                        (windMill:init())
                                    )(else
                                        (if (<= temp0 65)
                                            (if ((< (astroChicken:eggsLeft) 5) and not (send gCast:contains(cornStalk)))
                                                = local3 3
                                                = local4 Random(4 9)
                                            )
                                        )(else
                                            (if (<= temp0 80)
                                                (weasel:init())
                                            )(else
                                                (if (((<= temp0 85) and not (astroChicken:loop)) and not (send gCast:contains(chickenWire)))
                                                    (chickenWire:init())
                                                )(else
                                                    (if (not (send gCast:contains(rabidDog)))
                                                        (rabidDog:init())
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )


    (method (dispose)
        (send gSq4MouseDownHandler:delete(gCast gFeatures))
        (send gIconBar:enable())
        (send gGame:masterVolume(gGameMasterVolume))
        DisposeScript(949)
        (super:dispose())
    )


    (method (newRoom param1)
        (if (local0)
            proc0_12(local0)
        )
        (if (local1)
            proc0_12(local1)
        )
        (if (local9)
            proc0_12(local9)
        )
        (if (local10)
            proc0_12(local10)
        )
        (if (local12)
            proc0_12(local12)
        )
        (if (local13)
            proc0_12(local13)
        )
        (super:newRoom(rest param1))
    )

)
(class astroChicken of Actor
    (properties
        x 0
        y 0
        z 0
        heading 0
        noun 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        description 0
        sightAngle 26505
        actions 26505
        onMeCheck 26505
        lookStr 0
        yStep 2
        view 290
        loop 0
        cel 0
        priority 0
        underBits 0
        signal 2048
        lsTop 0
        lsLeft 0
        lsBottom 0
        lsRight 0
        brTop 0
        brLeft 0
        brBottom 0
        brRight 0
        palette 0
        cycleSpeed 0
        script 0
        cycler 0
        timer 0
        illegalBits 32768
        xLast 0
        yLast 0
        xStep 3
        moveSpeed 0
        blocks 0
        baseSetter 0
        mover 0
        looper 0
        viewer 0
        avoider 0
        code 0
        livesLeft 3
        eggsLeft 10
        wireLeft 0
    )

    (method (init)
        (var temp0[5])
        (send gLongSong:
            number(54)
            loop(-1)
            vol(127)
            playBed()
        )
        (super:init())
        (self:
            show()
            x(160)
            y(40)
            eggsLeft(10)
            loop(0)
            wireLeft(0)
            showEggs()
            showPts()
        )
        (astroIndicator:
            init()
            addToPic()
        )
        (send gSq4DirectionHandler:addToFront(self))
        (send gSq4KeyDownHandler:addToFront(self))
        (if (local12)
            proc0_12(local12)
        )
        (if (local13)
            proc0_12(local13)
        )
        = local12 proc0_12("Eggs:" 67 150 178 28 global136)
        = local13 proc0_12("Score:" 67 240 178 28 global136)
        (if (local1)
            proc0_12(local1)
        )
        = local1 proc0_12(Format(@temp0 "%d" local8) 67 275 178 28 global136 70 25)
    )


    (method (dispose)
        (send gSq4DirectionHandler:delete(self))
        (send gSq4KeyDownHandler:delete(self))
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (var temp0, temp1)
        (if (& (send pEvent:type) $0040)
            (send pEvent:claimed(1))
            (switch ((send pEvent:message))
                (case 7
                    (astroChicken:setMotion(MoveTo 0 (astroChicken:y)))
                )
                (case 3
                    (astroChicken:setMotion(MoveTo 320 (astroChicken:y)))
                )
                (case 1
                    (astroChicken:setMotion(MoveTo (astroChicken:x) 0))
                )
                (case 5
                    (astroChicken:setMotion(MoveTo (astroChicken:x) 190))
                )
            )
        )(else
            (if (== (send pEvent:type) 1)
                (send pEvent:claimed(1))
                (if (== (send pEvent:modifiers) 3)
                    (if ((eggsLeft and not (send gCast:contains(egg))) and (astroChicken:isNotHidden()))
                        (eggSquirt:play())
                        (egg:init())
                        --eggsLeft
                        (self:showEggs())
                    )
                )(else
                    = temp0 proc999_2(213 proc999_3(87 (send pEvent:x)))
                    (astroChicken:setMotion(MoveTo temp0 (send pEvent:y)))
                )
            )(else
                (if (== (send pEvent:type) 4)
                    (send pEvent:claimed(1))
                    (if ((((== (send pEvent:message) 13) and eggsLeft) and not (send gCast:contains(egg))) and (astroChicken:isNotHidden()))
                        (eggSquirt:play())
                        (egg:init())
                        --eggsLeft
                        (self:showEggs())
                    )
                )
            )
        )
    )


    (method (die)
        (if (not --livesLeft)
            Print("Game Over")
            (if (gTheNewDialog)
                (send gTheNewDialog:dispose())
            )
            (send global2:newRoom(376))
        )(else
            (winged:dispose())
            (send gCast:eachElementDo(103))
            (send global2:
                drawPic(290)
                style(15)
            )
            (self:init())
            (astroIndicator:
                cel(- (astroIndicator:cel) 1)
                init()
            )
        )
    )


    (method (showEggs)
        (var temp0[5])
        (if (local0)
            proc0_12(local0)
        )
        = local0 proc0_12(Format(@temp0 "%d" eggsLeft) 67 180 178 28 global136 70 25)
    )


    (method (showPts)
        (var temp0[5])
        (if (local1)
            proc0_12(local1)
        )
        = local1 proc0_12(Format(@temp0 "%d" local8) 67 275 178 28 global136 70 25)
    )


    (method (getEgg)
        (var temp0)
        ++eggsLeft
        = temp0 proc999_3(0 (- eggsLeft 8))
        (self:showEggs())
    )


    (method (incScore param1)
        (var temp0[41], temp41)
        (if (> param1 1)
            = local8 (+ local8 param1)
        )(else
            = temp41 (/ y 20)
            (if (param1)
                = local8 (+ local8 local14[temp41])
            )(else
                = local8 (+ local8 local20[temp41])
            )
        )
        (self:showPts())
    )

)
(class ScrollActor of Actor
    (properties
        x 0
        y 0
        z 0
        heading 0
        noun 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        description 0
        sightAngle 26505
        actions 26505
        onMeCheck 26505
        lookStr 0
        yStep 2
        view 290
        loop 0
        cel 0
        priority 12
        underBits 0
        signal 2064
        lsTop 0
        lsLeft 0
        lsBottom 0
        lsRight 0
        brTop 0
        brLeft 0
        brBottom 0
        brRight 0
        palette 0
        cycleSpeed 0
        script 0
        cycler 0
        timer 0
        illegalBits 32768
        xLast 0
        yLast 0
        xStep 3
        moveSpeed 0
        blocks 0
        baseSetter 0
        mover 0
        looper 0
        viewer 0
        avoider 0
        code 0
        scrollSpeed 9
        deathLoop 0
        deathMusic 0
    )

    (method (init)
        = nsRight (= nsBottom (= nsLeft (= nsTop 0)))
        (super:init())
        = x 350
    )


    (method (doit)
        (super:doit())
        (if (< (= x (- x scrollSpeed)) -50)
            (self:dispose())
        )(else
            (if ((astroChicken:isNotHidden()) and (self:onMe(astroChicken)))
                (self:doChicken())
            )(else
                (if ((send gCast:contains(egg)) and (self:onMe(egg)))
                    (self:doEgg())
                )
            )
        )
    )


    (method (cue)
        (astroChicken:die())
    )


    (method (doChicken)
        (if (deathLoop)
            (send gLongSong:stop())
            (eggSplatting:stop())
            (theSound:
                number(deathMusic)
                loop(1)
                play(self)
            )
            (astroChicken:hide())
            (self:
                setLoop(deathLoop)
                setCel(0)
                cycleSpeed(2)
                setCycle(End)
            )
        )
    )


    (method (doEgg)
    )

)
(instance hill of ScrollActor
    (properties
        y 143
        loop 11
        cel 4
    )

    (method (init)
        (self:setCel(Random(4 5)))
        (super:init())
    )

)
(instance grass of ScrollActor
    (properties
        loop 11
        cel 6
    )

    (method (init)
        (super:init())
        = scrollSpeed 11
        = x (+ x Random(0 150))
        = y 155
        (self:setPri(14))
    )

)
(instance rock of ScrollActor
    (properties
        y 143
        loop 11
        cel 7
        priority 13
    )

    (method (init)
        (super:init())
        = scrollSpeed 11
        = x (+ x Random(0 150))
        = y 155
        (self:setPri(14))
    )

)
(instance weasel of ScrollActor
    (properties
        illegalBits 0
        deathLoop 7
        deathMusic 55
    )

    (method (init)
        = scrollSpeed 13
        = loop 4
        = y (astroChicken:y)
        (super:init())
        (self:setCycle(Fwd))
    )


    (method (onMe param1)
        (var temp0)
        = temp0 0
        (if (not 
        (if (((<= nsLeft (send param1:x)) and (<= (send param1:x) (- nsRight 15))) and (<= (- nsTop 5) (send param1:y)))
            <= (send param1:y) (+ nsBottom 10)
        )
)
        )(else
            (if (== scrollSpeed 9)
            )(else
                (if ((astroChicken:loop))
                    (astroChicken:
                        wireLeft(- (astroChicken:wireLeft) 1)
                        incScore(5)
                    )
                    (weasel:scrollSpeed(9))
                    (if (not (astroChicken:wireLeft))
                        (astroChicken:setLoop(0))
                    )
                )(else
                    = temp0 1
                )
            )
        )
        return temp0
    )

)
(instance crazedFarmer of ScrollActor
    (properties
        loop 5
    )

    (method (init)
        = loop 5
        (if ((send gCast:contains(hill)))
            = y 130
        )(else
            = y 143
        )
        (super:init())
        = local2 10
    )


    (method (doit)
        (super:doit())
        (if (== loop 8)
        )(else
            (if ((not cycler and (astroChicken:isNotHidden())) and not --local2)
                (self:setCycle(End self))
            )
        )
        (if (((== loop 5) and (<= x (astroChicken:x))) and (astroChicken:isNotHidden()))
            (self:setLoop(6))
        )
    )


    (method (onMe param1)
        return 
            (if (((<= nsLeft (send param1:x)) and (<= (send param1:x) nsRight)) and (<= nsTop (send param1:y)))
                <= (send param1:y) (- nsBottom 15)
            )(else
                0
            )
    )


    (method (cue)
        (gunshot:play())
        (send ((buckShot:new())):init())
        (self:setCycle(Beg))
        = local2 Random(5 10)
    )


    (method (doEgg)
        (astroChicken:incScore(0))
        (eggFall:stop())
        (eggSplatting:play())
        (egg:
            hide()
            dispose()
        )
        (self:
            setLoop(8)
            setCel(0)
            setCycle(End)
        )
    )

)
(instance windMill of ScrollActor
    (properties
        loop 11
    )

    (method (init)
        (super:init())
        = y 105
        (self:setPri(13))
        (windMillBlade:init())
    )

)
(instance windMillBlade of ScrollActor
    (properties
        deathLoop 13
        deathMusic 55
    )

    (method (init)
        = loop 12
        (super:init())
        = y 105
        (self:
            setPri(14)
            setCycle(Fwd)
        )
    )

)
(instance cornStalk of ScrollActor
    (properties
        y 120
        loop 11
        cel 1
    )

    (method (init)
        (super:init())
        (send ((cornTop:new())):init())
    )

)
(instance cornTop of ScrollActor
    (properties
        y 120
        loop 11
        cel 2
    )

    (method (onMe param1)
        return 
            (if (((<= (- nsLeft 1) (send param1:x)) and (<= (send param1:x) (+ nsRight 2))) and (<= (- nsTop 10) (send param1:y)))
                <= (send param1:y) (+ nsBottom 15)
            )(else
                0
            )
    )


    (method (doChicken)
        (cornPicker:play())
        (astroChicken:getEgg())
        (self:hide())
    )

)
(instance rabidDog of ScrollActor
    (properties
        deathLoop 10
        deathMusic 140
    )

    (method (init)
        = loop 15
        = cycleSpeed (= cel 0)
        (if ((send gCast:contains(hill)))
            = y 130
        )(else
            = y 143
        )
        (super:init())
    )


    (method (onMe param1 param2)
        return 
            (if (== param1 astroChicken)
                return 
                    (if (((<= (- nsLeft 15) (send param1:x)) and (<= (send param1:x) (- nsRight 25))) and (<= (- nsTop 75) (send param1:y)))
                        <= (send param1:y) nsBottom
                    )(else
                        0
                    )
            )(else
                (super:onMe(param1 rest param2))
            )
    )


    (method (doChicken)
        (if ((== loop 15) and not cycler)
            (dogBarking:play())
            (if (< (- y (astroChicken:y)) 50)
                (super:doChicken())
            )(else
                (self:setCycle(End))
            )
        )
    )


    (method (doEgg)
        (astroChicken:incScore(1))
        (eggFall:stop())
        (eggSplatting:play())
        (egg:
            hide()
            dispose()
        )
        (self:
            setLoop(9)
            setCel(0)
            setCycle(End)
        )
    )

)
(instance chickenWire of ScrollActor
    (properties
        y 150
        loop 11
        cel 13
    )

    (method (init)
        (self:setCel(13))
        (super:init())
    )


    (method (doChicken)
        (cornPicker:play())
        (astroChicken:
            setLoop(1)
            wireLeft(3)
        )
        (self:setCel(14))
    )

)
(instance theCage of Cage
    (properties
        top 20
        left 75
        bottom 118
        right 225
    )
)
(instance astroIndicator of View
    (properties
        x 16
        y 185
        view 290
        loop 11
        cel 12
        priority 15
        signal 16
    )
)
(instance egg of Actor
    (properties
        view 290
        priority 13
        signal 2064
    )

    (method (init)
        (super:init())
        (eggFall:play())
        = x (astroChicken:x)
        = y (+ (astroChicken:y) 5)
        = local6 7
        = local7 1
        = local5 2
        (self:
            setLoop(2)
            setCycle(Fwd)
        )
    )


    (method (doit)
        (super:doit())
        (self:posn((+ x local6) (+ y local7)))
        (if (not --local5)
            --local6
            ++local7
            (if (>= y 150)
                (send ((eggSplat:new())):init())
                (self:dispose())
            )(else
                = local5 2
            )
        )
    )

)
(instance eggSplat of Actor
    (properties
        y 155
        view 290
        loop 3
        priority 12
        signal 2064
        xStep 9
    )

    (method (init)
        (super:init())
        (eggFall:stop())
        (eggSplatting:play())
        = x (egg:x)
        (self:
            setCycle(End)
            setMotion(MoveTo 65531 y self)
        )
    )


    (method (cue)
        (self:dispose())
    )

)
(instance buckShot of Actor
    (properties
        yStep 9
        view 290
        loop 11
        cel 3
        signal 30720
        illegalBits 0
    )

    (method (init)
        (super:init())
        = local2 0
        (self:
            posn((crazedFarmer:x) 108)
            setMotion(MoveTo (crazedFarmer:x) 65518 self)
        )
    )


    (method (doit)
        (super:doit())
        (if ((astroChicken:isNotHidden()) and (astroChicken:onMe(self)))
            (send gLongSong:stop())
            (eggFall:stop())
            (winged:play(astroChicken))
            (astroChicken:
                hide()
                die()
            )
            (self:dispose())
        )
    )


    (method (cue)
        (self:dispose())
    )

)
(instance henHouseLeft of Actor
    (properties
        x 500
        y 145
        view 290
        loop 11
        cel 8
        priority 3
        signal 22544
    )

    (method (doit param1)
        (super:doit(rest param1))
        (if (> x 169)
            = x (- x 9)
        )(else
            = x 160
        )
    )

)
(instance henHouseRight of Actor
    (properties
        x 500
        y 145
        view 290
        loop 11
        cel 9
        priority 12
        signal 22544
    )

    (method (doit param1)
        (super:doit(rest param1))
        (if (> x 169)
            = x (- x 9)
        )(else
            = x 160
        )
    )

)
(instance backok of Prop
    (properties
        x 100
        y 90
        view 290
        loop 14
    )
)
(instance astroChicken2 of Actor
    (properties
        view 290
        signal 2048
    )
)
(instance musicToggle of Feature
    (properties
        x 82
        y 177
        nsTop 176
        nsLeft 81
        nsBottom 188
        nsRight 117
    )

    (method (init)
        (super:init())
        (send gSq4MouseDownHandler:addToFront(self))
        (send gSq4KeyDownHandler:addToFront(self))
    )


    (method (dispose)
        (send gSq4MouseDownHandler:delete(self))
        (send gSq4KeyDownHandler:delete(self))
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (if (((== (send pEvent:type) 1) or ((== (send pEvent:type) 4) and (== (send pEvent:message) 19))) and (self:onMe(pEvent)))
            (if ((send gGame:masterVolume()))
                (send gGame:masterVolume(0))
            )(else
                (send gGame:masterVolume(gGameMasterVolume))
            )
            (send pEvent:claimed(1))
        )
    )

)
(instance startScript of Script
    (properties)

    (method (doit param1)
        (var newEvent, newEventType)
        (super:doit(rest param1))
        (if (< register 40)
            ++register
        )(else
            (self:cue())
        )
        (if (== state 0)
            = newEvent (Event:new())
            = newEventType (send newEvent:type)
            (if (proc999_5(newEventType 1 4))
                = seconds 0
                = cycles 1
            )
            (send newEvent:dispose())
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = local9 proc0_12("\"Flight of the Pullet.\"" 67 10 127 28 gColor 29 global132)
            )
            (case 1
                proc0_12(local9)
                (send global2:
                    drawPic(290)
                    style(15)
                )
                (astroChicken:
                    init()
                    setCycle(Fwd)
                    observeBlocks()
                    livesLeft(3)
                    showEggs()
                    showPts()
                )
                (send ((astroChicken:blocks)):add(theCage))
                (send client:setScript(0))
            )
        )
    )

)
(instance doHenHouse of Script
    (properties)

    (method (doit param1)
        (var newEvent, newEventType)
        (super:doit(rest param1))
        (if (== state 5)
            = newEvent (Event:new())
            = newEventType (send newEvent:type)
            (if (proc999_5(newEventType 1 4))
                = seconds 0
                = cycles 1
            )
            (send newEvent:dispose())
        )
    )


    (method (changeState newState)
        (var temp0[50])
        (switch (= state newState)
            (case 0
                = local8 (+ local8 (* (astroChicken:eggsLeft) 5))
                (if (local1)
                    proc0_12(local1)
                )
                = local1 proc0_12(Format(@temp0 "%d" local8) 67 275 178 28 global136 70 25)
                (astroChicken2:setMotion(MoveTo 100 100 self))
            )
            (case 1
                (astroChicken2:setMotion(MoveTo 104 129 self))
            )
            (case 2
                (astroChicken2:
                    setPri(11)
                    setMotion(MoveTo 174 129 self)
                )
            )
            (case 3
                (backok:
                    init()
                    setCycle(End)
                )
                = cycles 20
            )
            (case 4
                (backok:dispose())
                = cycles 2
            )
            (case 5
                = local9 proc0_12("Congratulations, in achieving the\ncoveted rank of \"Corn-Wheezer,\" you\nhave won the Pullet Surprise!\n" 67 0 20 28 gColor 29 global140 30 1)
                = local10 proc0_12(Format(@temp0 "5 X %d eggs = %d bonus points\n\nMega-Hi Score: %d" (astroChicken:eggsLeft) (* 5 (astroChicken:eggsLeft)) local8) 67 0 65 28 gColor 29 global136 30 1)
            )
            (case 6
                proc0_12(local9)
                proc0_12(local10)
                (send global2:newRoom(376))
            )
        )
    )

)
