(version 2)
(include "sci.sh")
(exports
    0 rm540
)
(use "Main")
(use "FPRoom")
(use "Print")
(use "n958")
(use "Jump")
(use "Cycle")
(use "View")
(use "Obj")
(script 540)


(local
    local0
    local1
    local2
    local3
    local4
    local5
    local6
    local7
    theTicks
    local9
    local10
    local11
    local12

)
(class WaverCode of Code
    (properties
        origX 0
        origY 0
    )

    (method (init)
        (var theOrigX, theOrigY)
        = origX theOrigX
        = origY theOrigY
    )


    (method (doit)
        (var temp0, temp1)
        (if (> GetDistance(gOrigX (- gPEventY 10) origX origY) local4)
            = origX gOrigX
            = origY (- gPEventY 10)
        )
        = temp0 
            (if (<= Random(5 10) 7)
                1
            )(else
                0
            )
        = temp1 
            (if (<= Random(5 10) 7)
                1
            )(else
                0
            )
        (if (temp0 and temp1)
            (send gGame:setCursor((send ((send gIconBar:at(5))):cursor) 1 (+ origX Random(1 local4)) origY))
        )(else
            (if (not temp0 and not temp1)
                (send gGame:setCursor((send ((send gIconBar:at(5))):cursor) 1 (- origX Random(1 local4)) origY))
            )(else
                (if (temp0 and not temp1)
                    (send gGame:setCursor((send ((send gIconBar:at(5))):cursor) 1 origX (- origY Random(1 local4))))
                )(else
                    (if (not temp0 and temp1)
                        (send gGame:setCursor((send ((send gIconBar:at(5))):cursor) 1 origX (+ origY Random(1 local4))))
                    )
                )
            )
        )
    )

)
(instance public rm540 of FPRoom
    (properties
        picture 780
    )

    (method (init)
        proc958_0(132 2546 2543 2541 2542 547 540)
        proc958_0(128 543 545 541 544 542 540)
        proc958_0(130 991)
        (super:init())
        (send gOldWH:addToFront(flyingBottle bottle hand))
        (self:setScript(sStartRoom))
    )


    (method (doit)
        (super:doit())
        (if (< gPEventY 10)
            (if (not local11)
                = local10 local4
                = local4 0
                = local11 1
            )
        )(else
            (if (local11 and (> gPEventY 26))
                = local4 local10
                = local11 0
            )
        )
        (if ((> local4 0) and (<= (- local6 gB_moveCnt) 0))
            (WaverCode:doit())
            = local6 (+ gB_moveCnt 10)
        )
        (send gEgo:get(-1 44))
    )


    (method (dispose)
        = global119 19
        (send gIconBar:enable())
        DisposeScript(991)
        (send gOldWH:delete(flyingBottle bottle hand))
        (super:dispose())
    )


    (method (handleEvent pEvent)
        return 
            (if (& (send pEvent:type) $0040)
                return 0
            )(else
                (super:handleEvent(pEvent))
            )
    )


    (method (doVerb theVerb param2)
        return 
            (switch (theVerb)
                (case 47
                    (gunSound:play())
                    return 0
                )
                (default 
                    (super:doVerb(theVerb rest param2))
                )
            )
    )

)
(instance sStartRoom of Script
    (properties)

    (method (changeState newState)
        (var temp0, temp1, temp2)
        (switch (= state newState)
            (case 0
                (send gGameMusic1:
                    number(540)
                    loop(-1)
                    play()
                )
                = cycles 5
            )
            (case 1
                (send gGame:setCursor(999 1))
                (switch ((Print:
                    font(gFont)
                    mode(1)
                    addTitle(3 0 1 1 540)
                    addButton(1 4 0 0 1 0 0 540)
                    addButton(2 4 0 0 2 0 18 540)
                    addButton(3 4 0 0 3 0 48 540)
                    init()
                )
)
                    (case 0
                        = local9 1
                        = cycles 2
                    )
                    (case 1
                        = local9 0
                        = cycles 2
                    )
                    (case 2
                        = local9 2
                        = cycles 2
                    )
                    (case 3
                        = local9 1
                        = cycles 2
                    )
                )
            )
            (case 2
                (send gGame:handsOn())
                (send gEgo:put(18))
                proc0_9(300)
                (send gIconBar:
                    curIcon((send gIconBar:useIconItem))
                    curInvIcon((send ((send gInv:at(44))):
                            cursor(10)
                            yourself()
                        )
)
                    enable((send gIconBar:at(5)))
                )
                (send ((send gIconBar:curIcon)):cursor(10))
                (send gGame:setCursor((send ((send gIconBar:at(5))):cursor)))
                (send gIconBar:select((send gIconBar:at(5))))
                (send gIconBar:disable(0 1 2 3 6))
                (send global2:drawPic(540))
                (WaverCode:init())
                = local7 1
                = local6 (+ gB_moveCnt 10)
                (switch (local9)
                    (case 0
                        = local1 6
                        = local0 3
                        = local3 5
                        = local4 15
                        = local5 1
                        = theTicks 60
                    )
                    (case 1
                        = local1 2
                        = local0 7
                        = local3 10
                        = local4 5
                        = local5 2
                        = theTicks 140
                    )
                    (case 2
                        = local1 4
                        = local0 4
                        = local3 7
                        = local4 10
                        = local5 2
                        = theTicks 100
                    )
                )
                = temp0 1
                (while (<= temp0 local1)
                    (switch (temp0)
                        (case 1
                            = temp1 25
                            = temp2 72
                        )
                        (case 2
                            = temp1 64
                            = temp2 68
                        )
                        (case 3
                            = temp1 104
                            = temp2 61
                        )
                        (case 4
                            = temp1 130
                            = temp2 67
                        )
                        (case 5
                            = temp1 171
                            = temp2 67
                        )
                        (case 6
                            = temp1 214
                            = temp2 71
                        )
                    )
                    (send ((bottle:new())):
                        init()
                        stopUpd()
                        loop(Random(0 2))
                        posn(temp1 temp2)
                    )
                    ++temp0
                )
                = cycles 10
            )
            (case 3
                (send gGame:setCursor(10 1))
                (send gFpMessager:say(6 0 0 0 self))
            )
            (case 4
                (self:dispose())
            )
        )
    )

)
(instance sCartoon of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ++global119
                (send gIconBar:disable())
                (send gUser:
                    canControl(0)
                    canInput(0)
                )
                (srini:init())
                (send gFpMessager:say(2 0 0 0 self))
            )
            (case 1
                (send gGameMusic2:
                    number(2543)
                    loop(1)
                    flags(1)
                    play()
                )
                (srini:dispose())
                (send gGame:setCursor((send ((send gIconBar:at(5))):cursor) 1 147 26))
                (sixBottles:
                    init()
                    setCycle(End self)
                    setMotion(JumpTo 113 40 self)
                )
            )
            (case 2
                (sixBottles:
                    setLoop(2)
                    setCycle(Fwd)
                )
            )
            (case 3
                (send gGameMusic2:
                    number(2542)
                    loop(1)
                    flags(1)
                    play()
                )
                (sixBottles:
                    setLoop(1)
                    cel(0)
                    setCycle(End self)
                )
                = local4 20
            )
            (case 4
                = local4 0
                (send gGame:setCursor(997 1))
                (send gGameMusic1:
                    number(547)
                    loop(1)
                    play(self)
                )
                (sixBottles:dispose())
            )
            (case 5
                (send gIconBar:enable())
                (send global2:newRoom(300))
                (self:dispose())
            )
        )
    )

)
(instance sGotHand of Script
    (properties)

    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                ++local2
                = temp0 
                    (if (== (hand:loop) 0)
                        2
                    )(else
                        3
                    )
                (hand:
                    setLoop(temp0)
                    setCel(0)
                    setCycle(End self)
                )
                (gunSound:play(self))
            )
            (case 1
            )
            (case 2
                = local4 (- local4 local5)
                (hand:dispose())
                (if (< local2 local1)
                    (send global2:setScript(sCardboardHand 0 0))
                )(else
                    = cycles 2
                )
            )
            (case 3
                (send gGame:points(5))
                = local2 0
                (send global2:setScript(sCartoon))
            )
        )
    )

)
(instance sGotFlyingBottle of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ++local2
                (flyingBottle:
                    setMotion(0)
                    setLoop(1)
                    setCycle(End self)
                )
            )
            (case 1
                (flyingBottle:hide())
                (send gGameMusic2:
                    number(2542)
                    loop(1)
                    flags(1)
                    play(self)
                )
            )
            (case 2
                = local4 (- local4 local5)
                (flyingBottle:dispose())
                (if (< local2 local1)
                    (send global2:setScript(sSriniThrows))
                )(else
                    (send gGame:points(5))
                    = local2 0
                    (send global2:setScript(sCardboardHand 0 1))
                )
            )
        )
    )

)
(instance sGotBottle of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = local7 0
                ++local2
                = cycles 2
            )
            (case 1
                (send gGameMusic2:
                    number(2542)
                    loop(1)
                    flags(1)
                    play(self)
                )
                (send client:setCycle(End self))
            )
            (case 2
                (if (== (send client:cel) (send client:lastCel()))
                    (send client:hide())
                )
            )
            (case 3
                = local4 (- local4 local5)
                (if (== local2 local1)
                    (send gGame:points(5))
                    (send global2:setScript(sSriniThrows))
                    = local2 0
                )(else
                    = local7 1
                )
                (send client:dispose())
                (self:dispose())
            )
        )
    )

)
(instance sSriniThrows of Script
    (properties)

    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                (srini:
                    init()
                    cel(0)
                )
                = ticks Random(30 240)
            )
            (case 1
                (srini:setCycle(End self))
            )
            (case 2
                (send gGameMusic2:
                    number(2543)
                    loop(1)
                    flags(1)
                    play()
                )
                (srini:dispose())
                (flyingBottle:
                    init()
                    setLoop(0)
                    cel(0)
                    posn(45 13)
                    setCycle(Fwd)
                    setStep(9 6)
                    setSpeed(local0)
                    ignoreHorizon()
                    setMotion(MoveTo 60 -20 self)
                )
                = local7 1
            )
            (case 3
                (flyingBottle:
                    posn(285 -20)
                    setMotion(MoveTo Random(266 320) 75 self)
                )
            )
            (case 4
                = local7 0
                (flyingBottle:dispose())
                (if (< local2 local1)
                    (self:changeState(0))
                )
            )
        )
    )

)
(instance sCardboardHand of Script
    (properties)

    (method (changeState newState)
        (var temp0, temp1, temp2, temp3)
        (switch (= state newState)
            (case 0
                (if (register)
                    = local4 0
                    (srini:
                        view(540)
                        init()
                    )
                    = ticks Random(30 240)
                )(else
                    (self:changeState(2))
                )
            )
            (case 1
                (send gFpMessager:say(1 0 0 0 self))
            )
            (case 2
                = ticks 60
            )
            (case 3
                (send gGame:setCursor((send ((send gIconBar:at(5))):cursor) 1 160 180))
                = temp0 Random(1 6)
                (if (register)
                    (srini:dispose())
                )
                (switch (temp0)
                    (case 1
                        = temp1 30
                        = temp2 107
                        = temp3 0
                    )
                    (case 2
                        = temp1 69
                        = temp2 99
                        = temp3 1
                    )
                    (case 3
                        = temp1 108
                        = temp2 95
                        = temp3 0
                    )
                    (case 4
                        = temp1 166
                        = temp2 100
                        = temp3 1
                    )
                    (case 5
                        = temp1 213
                        = temp2 102
                        = temp3 1
                    )
                    (case 6
                        = temp1 268
                        = temp2 112
                        = temp3 0
                    )
                )
                (send gGameMusic2:
                    number(2541)
                    loop(1)
                    flags(1)
                    play()
                )
                (hand:
                    init()
                    show()
                    setLoop(temp3)
                    cel(0)
                    posn(temp1 temp2)
                    setCycle(End self)
                )
                = local7 1
            )
            (case 4
                (hand:stopUpd())
                (if (not HaveMouse())
                    = ticks (* theTicks 2)
                )(else
                    = ticks theTicks
                )
            )
            (case 5
                (hand:setCycle(Beg self))
            )
            (case 6
                = local7 0
                (hand:dispose())
                (if (< local2 local1)
                    = register 0
                    (self:changeState(2))
                )
            )
        )
    )

)
(instance srini of Prop
    (properties
        x 15
        y 84
        noun 5
        view 542
    )

    (method (doVerb)
        (send gFpMessager:say(noun 47))
    )

)
(instance hand of Prop
    (properties
        view 544
    )

    (method (handleEvent pEvent)
        (send pEvent:claimed(1))
        (super:handleEvent(pEvent))
    )


    (method (onMe)
        (if (local7)
            = local7 0
            (if ((itsAHandHit:doit(self gOrigX gPEventY)))
                (send global2:setScript(sGotHand))
            )
        )
    )

)
(instance bottle of Prop
    (properties
        view 541
    )

    (method (handleEvent pEvent)
        (send pEvent:claimed(1))
        (super:handleEvent(pEvent))
    )


    (method (onMe)
        (if (not proc0_2(4))
            (self:cue())
        )
        (if (local7 and (itsAHit:doit(self gOrigX gPEventY)))
            = local7 0
            (self:setScript((sGotBottle:new())))
        )
    )


    (method (cue)
        (if (local12)
            = global122 11
            (send global2:newRoom(99))
        )(else
            (send gGameMusic2:
                number(2751)
                loop(1)
                flags(1)
                play(self)
            )
            ShakeScreen(24 2)
            = local12 1
        )
    )

)
(instance sixBottles of Actor
    (properties
        x 7
        y 84
        view 545
    )
)
(instance flyingBottle of Actor
    (properties
        x 45
        y 13
        view 543
    )

    (method (handleEvent pEvent)
        (send pEvent:claimed(1))
        (super:handleEvent(pEvent))
    )


    (method (onMe param1)
        (if (local7)
            = local7 0
            (if ((super:onMe(rest param1)))
                (send global2:setScript(sGotFlyingBottle))
            )
        )
    )

)
(instance itsAHit of Code
    (properties)

    (method (doit param1 param2 param3)
        return 
            (if (<= GetDistance(param2 param3 (send param1:x) (send param1:y)) local3)
                return 1
            )(else
                return 0
            )
    )

)
(instance itsAHandHit of Code
    (properties)

    (method (doit param1 param2 param3)
        (var temp0, temp1)
        (if ((send param1:loop))
            = temp0 (- (send param1:x) 20)
        )(else
            = temp0 (+ (send param1:x) 20)
        )
        = temp1 (- (send param1:y) 35)
        return 
            (if (<= GetDistance(param2 param3 temp0 temp1) local3)
                return 1
            )(else
                return 0
            )
    )

)
(instance gunSound of FPSound
    (properties
        flags $0001
        number 2101
    )
)
