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


(local
    newProp
    newAct
    gEgoX

)
(instance tickleSound of Sound
    (properties)
)
(instance fallSound of Sound
    (properties)
)
(instance bottleCage of Cage
    (properties
        top 144
        left 130
        bottom 175
        right 218
    )
)
(instance public Room44 of Rm
    (properties
        picture 44
        style 8
    )

    (method (init)
        = global101 1
        (super:init())
        Load(rsVIEW 52)
        Load(rsVIEW 17)
        Load(rsVIEW 19)
        Load(rsVIEW 7)
        Load(rsVIEW 6)
        Load(rsVIEW 53)
        Load(rsVIEW 49)
        Load(rsVIEW 21)
        Load(rsVIEW 51)
        Load(rsVIEW 73)
        Load(rsSOUND 51)
        (send gEgo:
            view(8)
            posn(39 161)
            viewer(inWhale)
            init()
        )
        (send (= newProp (Prop:new())):
            view(0)
            posn(161 76)
            init()
            hide()
        )
        (if ((send ((Inv:at(31))):ownedBy(44)))
            = newAct (Act:new())
            (send newAct:
                view(531)
                posn(201 167)
                xStep(1)
                yStep(1)
                setLoop(0)
                ignoreActors(0)
                illegalBits(32768)
                observeControl(4 1)
                setCycle(Fwd)
                setMotion(Wander 4)
                moveSpeed(8)
                cycleSpeed(2)
                observeBlocks(bottleCage)
                init()
            )
        )
        (send global2:setScript(deadTimer))
        Print(44 0)
        Print(44 1)
        = global183 1
    )


    (method (doit)
        (super:doit())
        (if (((& (send gEgo:onControl(0)) $0004) and (== (send gEgo:script()) 0)) and (== (deadTimer:state()) 0))
            (send gEgo:setScript(slide))
            (fallSound:
                number(51)
                play()
            )
            (if (== (send gEgo:view()) 2)
                (slide:changeState(10))
            )(else
                (slide:changeState(1))
            )
        )
    )


    (method (dispose)
        (send gTimers:eachElementDo(172 192))
        (send gSounds:eachElementDo(172))
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed()))
            return 1
        )
        return 
            (if (== (send pEvent:type()) 128)
                (if (Said('get,(look<in)/skeleton,man,person,james'))
                    Print(44 2)
                )(else
                    (if (Said('get,capture/fish') or Said('fish'))
                        Print(44 3)
                    )(else
                        (if (Said('get,drink[/drink,water]'))
                            Print(44 4)
                        )(else
                            (if (Said('get/boat'))
                                Print(44 5)
                            )(else
                                (if (Said('get/bottle'))
                                    (if ((send ((Inv:at(31))):ownedBy(44)))
                                        (if (< (send gEgo:distanceTo(newAct)) 15)
                                            Print(44 6)
                                            (send newAct:dispose())
                                            = global182 1
                                            (send gEgo:get(31))
                                        )(else
                                            Print(800 1)
                                        )
                                    )(else
                                        (if ((send gEgo:has(31)))
                                            Print(44 7)
                                        )(else
                                            Print(44 8)
                                        )
                                    )
                                )(else
                                    (if (Said('>,ignite,create,begin/fire'))
                                        Print(44 9)
                                    )(else
                                        (if (Said('look>'))
                                            (if (Said('/fish'))
                                                Print(44 10)
                                            )(else
                                                (if (Said('/boat'))
                                                    Print(44 11)
                                                )(else
                                                    (if (Said('<under/water'))
                                                        Print(44 12)
                                                    )(else
                                                        (if (Said('/)'))
                                                            Print(44 13)
                                                        )(else
                                                            (if (Said('/tongue'))
                                                                Print(44 14)
                                                            )(else
                                                                (if (Said('/esophagus,lips,molar'))
                                                                    Print(44 15)
                                                                )(else
                                                                    (if (Said('/uvula'))
                                                                        Print(44 16)
                                                                    )(else
                                                                        (if (Said('/skeleton,james,man,person'))
                                                                            Print(44 17)
                                                                        )(else
                                                                            (if (Said('/water'))
                                                                                (if ((send ((Inv:at(31))):ownedBy(44)))
                                                                                    Print(44 18)
                                                                                )(else
                                                                                    Print(44 19)
                                                                                )
                                                                            )(else
                                                                                (if (Said('[<up,around,at][/room,whale]'))
                                                                                    Print(44 0)
                                                                                    Print(44 1)
                                                                                )
                                                                            )
                                                                        )
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )(else
                                            (if (Said('hit/molar'))
                                                (if (< (send gEgo:y()) 82)
                                                    Print(44 20)
                                                )(else
                                                    Print(800 1)
                                                )
                                            )(else
                                                (if (Said('hit/tongue'))
                                                    Print(44 21)
                                                )(else
                                                    (if (Said('hit/uvula,esophagus'))
                                                        (if ((send gEgo:inRect(140 71 178 86)))
                                                            Print(44 22)
                                                        )(else
                                                            Print(800 1)
                                                        )
                                                    )(else
                                                        (if (Said('climb'))
                                                            Print(44 23)
                                                        )(else
                                                            (if (Said('call,help') or Said(',/&'))
                                                                Print(44 24)
                                                            )(else
                                                                (if (Said('/'))
                                                                    Print(44 25)
                                                                )(else
                                                                    (if (Said('bathe'))
                                                                        Print(44 26)
                                                                    )(else
                                                                        (if (Said('open,force/lips'))
                                                                            Print(44 27)
                                                                        )(else
                                                                            (if (Said('>/fire'))
                                                                                Print(44 9)
                                                                            )(else
                                                                                (if (Said('tickle'))
                                                                                    (if ((send gEgo:has(8)))
                                                                                        (if ((send gEgo:inRect(140 71 178 86)))
                                                                                            (send gEgo:setScript(tickle))
                                                                                            (tickle:changeState(1))
                                                                                            (send gGame:changeScore(5))
                                                                                        )(else
                                                                                            Print(44 28)
                                                                                        )
                                                                                    )(else
                                                                                        Print(44 29)
                                                                                    )
                                                                                )
                                                                            )
                                                                        )
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )(else
                0
            )
    )

)
(instance slide of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 1
                (proc0_10() 
                (if (< (send gEgo:x()) 50)
                    = gEgoX (+ (send gEgo:x()) 20)
                )(else
                    (if (> (send gEgo:x()) 270)
                        = gEgoX (- (send gEgo:x()) 20)
                    )(else
                        = gEgoX (send gEgo:x())
                    )
                )
 (send gEgo:
                    view(52)
                    illegalBits(0)
                    setLoop(2)
                    setCycle(Fwd)
                    yStep(5)
                    xStep(3)
                    setMotion(MoveTo gEgoX 145 self)
                )
  )
            )
            (case 2
                ((send gEgo:
                    view(19)
                    setLoop(0)
                    cel(2)
                    setCycle(End self)
                )
  )
            )
            (case 3
                ((fallSound:dispose()) (send gEgo:viewer(inWhale)) (send gEgo:
                    illegalBits(32768)
                    setLoop(-1)
                    xStep(2)
                    yStep(1)
                    setScript(0)
                )
 proc0_11()  )
            )
            (case 10
                (proc0_10() (send gEgo:
                    view(17)
                    setLoop(& (send gEgo:loop()) $0001)
                )
 (send gEgo:
                    illegalBits(0)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 11
                ((self:changeState(1)) )
            )
        )
    )

)
(instance inWhale of Script
    (properties)

    (method (doit)
        (super:doit())
        (if (== (send gEgo:script()) 0)
            (if (& (send gEgo:onControl(1)) $0200)
                (send gEgo:
                    view(8)
                    xStep(2)
                    yStep(1)
                    setCycle(Fwd)
                )
            )(else
                (if (& (send gEgo:onControl(1)) $0008)
                    (send gEgo:
                        view(7)
                        xStep(2)
                        yStep(1)
                        setCycle(Walk)
                    )
                )(else
                    (if (& (send gEgo:onControl(1)) $0800)
                        (send gEgo:
                            view(6)
                            xStep(2)
                            yStep(1)
                            setCycle(Walk)
                        )
                    )(else
                        (if (& (send gEgo:onControl(1)) $0001)
                            (if (== (send gEgo:view()) 2)
                                (slide:changeState(1))
                            )(else
                                (send gEgo:
                                    view(53)
                                    setCycle(Walk)
                                    setStep(1 1)
                                )
                            )
                        )(else
                            (if ((<> (send gEgo:view()) 2) and (& (send gEgo:onControl(1)) $0010))
                                (self:changeState(1))
                            )
                        )
                    )
                )
            )
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 1
                (
                (if (<> (send gEgo:view()) 2)
                    proc0_10()
                    (send gEgo:
                        viewer(0)
                        view(49)
                        setMotion(0)
                        loop(& (send gEgo:loop()) $0001)
                        cel(4)
                        setCycle(Beg self)
                    )
                )
 )
            )
            (case 2
                ((send gEgo:
                    view(21)
                    cel(6)
                    setCycle(Beg self)
                )
  )
            )
            (case 3
                ((send gEgo:
                    view(2)
                    setStep(2 1)
                    setCycle(Walk)
                    viewer(inWhale)
                )
 = state 0 proc0_11() )
            )
        )
    )

)
(instance tickle of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 1
                (proc0_10() (send gTimers:eachElementDo(172 192)) (send global2:script(0)) (tickleSound:
                    number(60)
                    play(self)
                )
 (send gEgo:
                    setMotion(0)
                    viewer(0)
                )
 proc0_3(gEgo newProp) (send gEgo:loop((& (send gEgo:loop()) $0001))) (send gEgo:
                    view(51)
                    loop(& (send gEgo:loop()) $0001)
                    setCycle(Fwd)
                )
  )
            )
            (case 2
                (Print(44 30) (send gEgo:
                    setLoop(-1)
                    setCel(-1)
                )
 proc0_11() (send global2:newRoom(31)) )
            )
        )
    )

)
(instance deadTimer of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (
                (if ((send gEgo:has(8)))
                    (send (ScriptID(0 5)):setReal(self 1 4))
                )(else
                    (send (ScriptID(0 5)):setReal(self 2 1))
                )
 )
            )
            (case 1
                ((send gEgo:viewer(0)) 
                (if (> (inWhale:state()) 0)
                    --state
                    = seconds 2
                )(else
                    (self:cue())
                )
 )
            )
            (case 2
                (proc0_10() (send gSounds:eachElementDo(172)) 
                (if (< (send gEgo:x()) 50)
                    = gEgoX (+ (send gEgo:x()) 20)
                )(else
                    (if (> (send gEgo:x()) 270)
                        = gEgoX (- (send gEgo:x()) 20)
                    )(else
                        = gEgoX (send gEgo:x())
                    )
                )
 
                (if (== (send gEgo:view()) 2)
                    (self:changeState(10))
                )(else
                    (if (== (send gEgo:view()) 53)
                        (fallSound:
                            number(51)
                            play()
                        )
                        (send gEgo:
                            view(52)
                            setLoop(2)
                            setCycle(Fwd (send gEgo:yStep(5)))
                            setMotion(MoveTo gEgoX 145 self)
                        )
                    )(else
                        (self:changeState(4))
                    )
                )
 )
            )
            (case 3
                ((send gEgo:
                    view(19)
                    setLoop(0)
                    cel(2)
                    setCycle(End self)
                )
  )
            )
            (case 4
                ((self:changeState(20))  )
            )
            (case 10
                ((fallSound:
                    number(51)
                    play()
                )
 (send gEgo:
                    setLoop(& (send gEgo:loop()) $0001)
                    view(17)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 11
                ((send gEgo:
                    view(52)
                    setLoop(2)
                    setCycle(Fwd)
                    yStep(5)
                    xStep(3)
                    illegalBits(0)
                    setMotion(MoveTo gEgoX 145 self)
                )
  )
            )
            (case 12
                ((self:changeState(3))  )
            )
            (case 20
                ((send gEgo:
                    view(73)
                    setLoop(0)
                    cel(6)
                    setCycle(End self)
                )
  )
            )
            (case 21
                ((send gEgo:hide()) Print(44 31) (send (ScriptID(0 5)):setReal(self 5))  )
            )
            (case 22
                (= global127 1 )
            )
        )
    )

)
