(version 2)
(include "sci.sh")
(exports
    0 aardvarkEntrance
    1 aardvarkTalker
    2 cleanUp
)
(use "Main")
(use "TellerIcon")
(use "Blink")
(use "Cycle")
(use "User")
(use "View")
(use "Obj")
(script 402)


(local
    local0
    theClient
    local2[8] = (0 -14 13 -11 -8 7 12 999 )
    local10[6] = (0 15 16 17 18 999 )
    local16[6] = (0 19 20 21 9 999 )
    local22[4] = (0 9 10 999 )
    local26[10]
    local36[5] = (0 -14 -11 -8 999 )
    local41[4] = (0 22 -23 999 )
    local45[6]

)
(instance public aardvarkEntrance of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                = local0 global120
                = theClient client
                = local26[0] @local2
                = local26[1] @local10
                = local26[2] @local16
                = local26[3] @local22
                = local45[0] @local41
                (aardvark:init())
                (aardvarkTell:init(aardvark @local2 @local26 @local36))
                (egoTell:init(gOwner @local41 @local45))
                (send gQg3Messager:say(2 6 27 0 self 400))
            )
            (case 1
                (send gOwner:setCycle(Beg self))
            )
            (case 2
                (send gOwner:
                    x(+ (send gOwner:x) 25)
                    normalize()
                )
                (aardvark:
                    setLoop(0)
                    setCycle(Walk)
                    setMotion(MoveTo 67 149 self)
                )
            )
            (case 3
                (aardvark:
                    loop(2)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 4
                (send gQg3Messager:say(2 6 5 0 self 400))
            )
            (case 5
                (aardvark:
                    loop(3)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 6
                (aardvark:
                    loop(4)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 7
                (send gQg3Messager:say(2 6 6 0 self 400))
            )
            (case 8
                (aardvark:
                    loop(5)
                    cel(0)
                )
                (send gMainIconBar:enable(4 2))
                (User:canInput(1))
                (send gMainIconBar:advanceCurIcon())
                (aardvark:setScript(drink))
                (self:dispose())
            )
        )
    )

)
(instance drink of Script
    (properties)

    (method (doit)
        = global120 local0
        (super:doit())
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (aardvark:setCycle(End self))
            )
            (case 1
                (aardvark:setCycle(Beg self))
            )
            (case 2
                = cycles 300
            )
            (case 3
                (self:init())
            )
        )
    )

)
(instance aardvark of Actor
    (properties
        x -10
        y 149
        noun 2
        view 404
    )

    (method (doit param1)
        Palette(palANIMATE 67 69 2)
        (super:doit(rest param1))
    )

)
(instance public aardvarkTalker of Talker
    (properties
        x 0
        y 0
        view 405
        loop 1
        cel 1
        priority 11
        signal $0010
        talkWidth 150
        back 57
        textX 137
        textY 5
    )

    (method (init)
        (super:init(aardvarkCandle aardvarkEyes aardvarkMouth))
    )


    (method (doit)
        (if ((super:doit()) and mouth)
            (self:cycle(mouth))
        )
        (if (bust)
            (self:cycle(bust))
        )
        (if (eyes)
            (self:cycle(eyes))
        )
    )


    (method (dispose param1)
        (if (mouth and underBits)
            (send mouth:cel(0))
            DrawCel((send mouth:view) (send mouth:loop) 0 + (send mouth:nsLeft) nsLeft + (send mouth:nsTop) nsTop -1)
        )
        (if (mouth and (send mouth:cycler))
            (if ((send ((send mouth:cycler)):respondsTo(#cue)))
                (send ((send mouth:cycler)):cue())
            )
            (send mouth:setCycle(0))
        )
        (if (not paramTotal or param1)
            (if (bust and underBits)
                (send bust:
                    setCycle(0)
                    cel(0)
                )
                DrawCel((send bust:view) (send bust:loop) 0 + (send bust:nsLeft) nsLeft + (send bust:nsTop) nsTop -1)
            )
            (if (eyes and underBits)
                (send eyes:
                    setCycle(0)
                    cel(0)
                )
                DrawCel((send eyes:view) (send eyes:loop) 0 + (send eyes:nsLeft) nsLeft + (send eyes:nsTop) nsTop -1)
            )
            (self:hide())
        )
        (super:dispose(param1))
    )


    (method (show)
        (var temp0)
        (if (not underBits)
            = underBits Graph(grSAVE_BOX nsTop nsLeft nsBottom nsRight 1)
        )
        = temp0 PicNotValid()
        PicNotValid(1)
        DrawCel(view loop cel nsLeft nsTop -1)
        (if (bust)
            DrawCel((send bust:view) (send bust:loop) (send bust:cel) + (send bust:nsLeft) nsLeft + (send bust:nsTop) nsTop -1)
        )
        (if (eyes)
            DrawCel((send eyes:view) (send eyes:loop) (send eyes:cel) + (send eyes:nsLeft) nsLeft + (send eyes:nsTop) nsTop -1)
        )
        (if (mouth)
            DrawCel((send mouth:view) (send mouth:loop) (send mouth:cel) + (send mouth:nsLeft) nsLeft + (send mouth:nsTop) nsTop -1)
        )
        Graph(grUPDATE_BOX nsTop nsLeft nsBottom nsRight 1)
        PicNotValid(temp0)
    )


    (method (startText)
        (var temp0[21])
        (if (bust)
            (send bust:setCycle(Fwd))
        )
        (super:startText())
    )

)
(instance aardvarkEyes of Prop
    (properties
        nsTop 45
        nsLeft 45
        view 405
        loop 2
        cel 1
        priority 15
        signal $0010
    )
)
(instance aardvarkCandle of Prop
    (properties
        nsTop 5
        nsLeft 49
        view 405
        loop 3
        priority 15
        signal $0010
        cycleSpeed 10
    )
)
(instance aardvarkMouth of Prop
    (properties
        nsTop 53
        nsLeft 41
        view 405
        cel 4
        priority 14
        signal $0010
    )
)
(instance aardvarkTell of Teller
    (properties)
)
(instance egoTell of Teller
    (properties)

    (method (doChild param1)
        return 
            (if (== param1 -23)
                (send theClient:setScript(cleanUp theClient))
                return 1
            )(else
                0
            )
    )

)
(instance public cleanUp of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                = cycles 10
            )
            (case 1
                (drink:dispose())
                (aardvark:setCycle(End self))
            )
            (case 2
                (aardvark:
                    loop(6)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 3
                (aardvark:
                    loop(3)
                    cel(6)
                    setCycle(Beg self)
                )
            )
            (case 4
                (aardvark:
                    loop(1)
                    setCycle(Walk)
                    setMotion(MoveTo -20 149 self)
                )
            )
            (case 5
                (send gOwner:
                    view(35)
                    loop(1)
                    cel(0)
                    x(- (send gOwner:x) 25)
                    setCycle(End self)
                )
                (aardvarkTell:dispose())
                (aardvarkTalker:dispose())
                (aardvark:dispose())
                (egoTell:dispose())
                (send gLongSong:
                    number(927)
                    setLoop(-1)
                    play()
                )
            )
            (case 6
                = seconds 5
            )
            (case 7
                PalVary(pvREVERSE 3)
                proc0_5(81)
                = seconds 4
            )
            (case 8
                (send (ScriptID(7 7)):init(5 40))
                = cycles 10
            )
            (case 9
                (send gOwner:setCycle(Beg self))
            )
            (case 10
                (send gOwner:
                    normalize()
                    x(+ (send gOwner:x) 25)
                )
                (self:dispose())
            )
        )
    )

)
