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


(local
    newProp
    local1
    local2
    local3
    newView
    newAct
    newAct_2
    local7
    newProp_2
    newAct_3
    local10
    local11
    local12
    local13

)
(instance whaleMusic of Sound
    (properties)
)
(instance sharkMusic of Sound
    (properties)
)
(instance public Room31 of Rm
    (properties
        style 9
    )

    (method (init)
        = horizon 75
        = global101 0
        = local12 4
        = newProp (Prop:new())
        (send newProp:
            view(650)
            loop(1)
            cel(1)
            posn(155 58)
            setPri(0)
            ignoreActors()
            setCycle(Fwd)
            init()
            hide()
        )
        (self:setRegions(519 504))
        Load(rsVIEW 8)
        Load(rsVIEW 10)
        Load(rsVIEW 300)
        Load(rsVIEW 300)
        Load(rsVIEW 84)
        Load(rsVIEW 887)
        Load(rsSOUND 78)
        Load(rsSOUND 36)
        (if (<= (send gEgo:y()) (+ gHorizon 2))
            (send gEgo:y((- horizon 1)))
        )
        = gHorizon horizon
        (switch (gPicture)
            (case 43
                (
                (if (== (send gEgo:view()) 312)
                    (if (global100)
                        (send global2:drawPic(131))
                    )(else
                        (send global2:drawPic(31))
                    )
                    = local2 4
                    = local1 2
                    (User:canControl(0))
                    = global205 1
                    (send gEgo:
                        posn(5 100)
                        setMotion(MoveTo 400 114)
                    )
                )(else
                    = local2 100
                    = local1 100
                )
 )
            )
            (case 44
                (= local2 99 = local1 100 (send (= newView (View:new())):
                    view(526)
                    loop(0)
                    cel(0)
                    posn(134 55)
                    init()
                )
 (send newProp:hide()) 
                (if (global100)
                    (send global2:drawPic(131))
                )(else
                    (send global2:drawPic(31))
                )
 (send gEgo:setScript(whaleActions)) (whaleActions:changeState(10))  )
            )
            (case 1
                (= local2 4 = local1 0  )
            )
            (case 95
                (= local2 3 = local1 1  )
            )
            (case 13
                (= local2 2 = local1 0  )
            )
            (case 19
                (= local2 1 = local1 0  )
            )
            (case 25
                (= local2 0 = local1 0  )
            )
            (case 32
                (
                (if (<= (send gEgo:x()) 0)
                    = local2 1
                    = local1 5
                )(else
                    (if (>= (send gEgo:y()) 189)
                        = local2 1
                        = local1 3
                    )(else
                        (if (>= (send gEgo:x()) 319)
                            = local2 1
                            = local1 3
                        )(else
                            = local2 1
                            = local1 3
                        )
                    )
                )
 )
            )
            (case 39
                (= local2 2 = local1 5  )
            )
            (case 41
                (= local1 3 = local2 2  )
            )
            (case 36
                (= local2 3 = local1 5  )
            )
            (case 38
                (= local2 3 = local1 3  )
            )
            (case 33
                (= local2 4 = local1 5  )
            )
            (case 34
                (= local2 4 = local1 4  )
            )
            (case 35
                (= local2 4 = local1 3 )
            )
        )
        = local3 0
        = local11 0
        (if (<> (send gEgo:view()) 312)
            (if (<> (send gEgo:view()) 84)
                (send gEgo:setCycle(Fwd))
                (send gEgo:
                    view(8)
                    init()
                    hide()
                    xStep(2)
                    yStep(1)
                )
            )
        )(else
            (send gEgo:setCycle(Fwd))
            (send gEgo:
                init()
                xStep(4)
                yStep(2)
            )
        )
        (if ((((((== global109 1) and (< Random(1 100) 40)) and (<> global105 14)) and (== global183 0)) and (< local1 30)) and (<> (send gEgo:script()) sharkActions))
            (send gEgo:setScript(whaleActions))
        )
        (send gEgo:edgeHit(0))
        (super:init())
        (self:doit())
        = local13 local2
    )


    (method (doit)
        (super:doit())
        (if ((not global100 and (== (send global2:script()) 0)) and (== Random(1 100) 9))
            (send global2:setScript(fish3Actions))
        )
        (if (((== (send global2:script()) 0) and not global100) and (== Random(1 100) 10))
            (send global2:setScript(fishActions))
        )
        (if ((send gEgo:edgeHit()))
            ++local3
            = global136 local1
            = global137 local2
            (if (<> (send gEgo:view()) 312)
                (if ((== local3 1) and global100)
                    = local1 1000
                    = local2 1000
                )
                (if (== local3 4)
                    Print(31 17)
                )
                (if ((== local3 local12) and (<> (send gEgo:script()) sharkActions))
                    (send gEgo:setScript(drown))
                    (drown:changeState(1))
                    1
                )
            )
            (if (== (send gEgo:edgeHit()) 1)
                (if ((< ++local2 10) and (> local2 4))
                    = local2 0
                )
                (send gEgo:posn((send gEgo:x()) 188))
            )(else
                (if (== (send gEgo:edgeHit()) 3)
                    (if (< --local2 0)
                        = local2 4
                    )
                    (send gEgo:posn((send gEgo:x()) (+ horizon (+ (send gEgo:yStep()) 2))))
                )(else
                    (if (== (send gEgo:edgeHit()) 2)
                        --local1
                        (send gEgo:posn(1 (send gEgo:y())))
                    )(else
                        (if (== (send gEgo:edgeHit()) 4)
                            ++local1
                            (send gEgo:posn(318 (send gEgo:y())))
                        )
                    )
                )
            )
            (if ((== local1 100) and (== local2 100))
                (send global2:newRoom(43))
            )(else
                (if ((== local1 1) and (== local2 3))
                    (send global2:newRoom(95))
                )(else
                    (if (== local1 0)
                        (switch (local2)
                            (case 4
                                (send global2:newRoom(1))
                            )
                            (case 2
                                (send global2:newRoom(13))
                            )
                            (case 1
                                (send global2:newRoom(19))
                            )
                            (case 0
                                (send global2:newRoom(25))
                            )
                        )
                    )(else
                        (if ((== local2 1) and (((== local1 3) or (== local1 4)) or (== local1 5)))
                            (send global2:newRoom(32))
                        )(else
                            (if ((== local2 2) and (== local1 3))
                                (send global2:newRoom(41))
                            )(else
                                (if ((== local2 2) and (== local1 5))
                                    (send global2:newRoom(39))
                                )(else
                                    (if ((== local2 3) and (== local1 3))
                                        (if (== local13 4)
                                            (send gEgo:y(100))
                                            (send global2:newRoom(41))
                                        )(else
                                            (send gEgo:y(170))
                                            (send global2:newRoom(35))
                                        )
                                    )(else
                                        (if ((== local2 3) and (== local1 5))
                                            (if (<= (send gEgo:y()) 120)
                                                (send global2:newRoom(33))
                                            )(else
                                                (send global2:newRoom(39))
                                            )
                                        )(else
                                            (if ((== local2 4) and (== local1 3))
                                                (if (<> (send gEgo:view()) 312)
                                                    (send global2:newRoom(35))
                                                )
                                            )(else
                                                (if ((== local2 4) and (== local1 4))
                                                    (if (<> (send gEgo:view()) 312)
                                                        (send global2:newRoom(34))
                                                    )
                                                )(else
                                                    (if (((== local2 4) and (== local1 5)) and (<> (send gEgo:view()) 312))
                                                        (send global2:newRoom(33))
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
            (if (== (send gEgo:script()) sharkActions)
                (if ((send gCast:contains(newAct_3)))
                    (if (< (send gEgo:x()) 10)
                        (send newAct_3:posn((- (send gEgo:x()) 20) (send gEgo:y())))
                    )(else
                        (if (< (send gEgo:y()) (+ horizon 10))
                            (send newAct_3:posn((send gEgo:x()) (- horizon 10)))
                        )(else
                            (if (> (send gEgo:x()) 300)
                                (send newAct_3:posn(339 (send gEgo:y())))
                            )(else
                                (if (> (send gEgo:y()) 174)
                                    (send newAct_3:posn((send gEgo:x()) 204))
                                )(else
                                    (send newAct_3:posn((- (send gEgo:x()) 20) (- (send gEgo:y()) 20)))
                                )
                            )
                        )
                    )
                )
            )(else
                (if (((((((== local2 0) and (> local1 2)) and (<= local1 5)) or (((== local2 0) and (<= local1 2)) and (> Random(1 100) 50))) or (>= Random(1 100) 75)) or ((<> global100 0) and (<= Random(100) 50))) and (((<> (send gEgo:view()) 312) and (<> (send gEgo:script()) sharkActions)) and (<> (send gEgo:script()) whaleActions)))
                    (send gEgo:setScript(sharkActions))
                )
            )
            (if (== gTheGGNewPropX 31)
                (if ((send gCast:contains(newAct)))
                    (send newAct:dispose())
                    (send global2:setScript(0))
                )
                (if ((send gCast:contains(newAct_2)))
                    (send newAct_2:dispose())
                    (send global2:setScript(0))
                )
                (if (not 
                (if (== local2 99)
                    (== local1 100)
                )
 and (send gCast:contains(newView)))
                    (send newView:dispose())
                    (send newProp:show())
                )
                (if (global100)
                    (send gAddToPics:dispose())
                    (send global2:drawPic(131 9))
                    (if ((send gCast:contains(newProp_2)))
                        (send gEgo:setScript(0))
                        (send newProp_2:dispose())
                        (whaleMusic:dispose())
                    )
                )(else
                    (send gAddToPics:dispose())
                    (send global2:drawPic(31 9))
                    (if ((send gCast:contains(newProp_2)))
                        (send gEgo:setScript(0))
                        (send newProp_2:dispose())
                        (whaleMusic:dispose())
                    )
                )
                (if ((== local1 100) and (== local2 99))
                    (if (not (send gCast:contains(newView)))
                        (send (= newView (View:new())):
                            view(526)
                            loop(0)
                            cel(0)
                            posn(134 55)
                            init()
                        )
                        (send newProp:hide())
                    )
                )(else
                    (send newProp:show())
                )
                (if (not global100)
                    (send ((View:new())):
                        view(671)
                        cel(Random(0 9))
                        x(Random(10 319))
                        y(Random(20 30))
                        setPri(0)
                        ignoreActors()
                        init()
                        addToPic()
                    )
                    (send ((View:new())):
                        view(671)
                        cel(Random(0 9))
                        x(Random(10 319))
                        y(Random(20 30))
                        setPri(0)
                        ignoreActors()
                        init()
                        addToPic()
                    )
                    (send ((View:new())):
                        view(671)
                        cel(Random(0 9))
                        x(Random(10 319))
                        y(Random(20 30))
                        setPri(0)
                        ignoreActors()
                        init()
                        addToPic()
                    )
                )
                (if (<> (send gEgo:view()) 312)
                    (send gEgo:
                        setMotion(0)
                        show()
                    )
                )
            )
        )
    )


    (method (dispose)
        (send gTimers:eachElementDo(172 192))
        (send gEgo:setLoop(-1))
        (send gSounds:eachElementDo(172))
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (var gInvSaidMe)
        (if ((send pEvent:claimed()))
            return 1
        )
        return 
            (if (== (send pEvent:type()) 128)
                (if (Said('look[<around][/room,ocean,ocean,water]'))
                    (if ((== local2 99) and (== local1 100))
                        Print(31 0)
                    )(else
                        (if (global100)
                            Print(31 1)
                        )(else
                            (if (== global105 14)
                                Print(31 2)
                            )(else
                                Print(31 3)
                            )
                        )
                    )
                    (if ((send gCast:contains(newAct_3)))
                        Print(31 4)
                    )
                )(else
                    (if (Said('mount/dolphin'))
                        (if (== (send gEgo:view()) 312)
                            Print(31 5)
                        )(else
                            Print(31 6)
                        )
                    )(else
                        (if (Said('/shark'))
                            (if ((send gCast:contains(newAct_3)))
                                Print(31 7)
                            )(else
                                Print(31 6)
                            )
                        )(else
                            (if (Said('look/island'))
                                (if ((== local2 99) and (== local1 100))
                                    Print(31 8)
                                )(else
                                    Print(31 9)
                                )
                            )(else
                                (if (== (send gEgo:view()) 312)
                                    (if (Said('look/dolphin'))
                                        Print(31 10)
                                    )(else
                                        (if (Said('kiss/dolphin'))
                                            Print(31 11)
                                        )(else
                                            (if (Said('deliver>'))
                                                (if (Said('/*/fish'))
                                                    Print(31 12)
                                                )(else
                                                    (if (Said('/*/bird,gull'))
                                                        Print(31 13)
                                                    )(else
                                                        (if (Said('/*/dolphin>') and (= gInvSaidMe (send gInv:saidMe())))
                                                            (if ((send gEgo:has((send gInv:indexOf((= gInvSaidMe (send gInv:saidMe())))))))
                                                                Print(31 14)
                                                            )(else
                                                                proc0_19()
                                                            )
                                                        )
                                                    )
                                                )
                                            )(else
                                                (if (Said('converse[/dolphin]'))
                                                    Print(31 15)
                                                )(else
                                                    (if (Said('pat/dolphin'))
                                                        Print(31 16)
                                                    )(else
                                                        (send pEvent:claimed(0))
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )(else
                0
            )
    )

)
(instance fish3Actions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= newAct (Act:new()) = local10 Random(5 304) = local7 Random((+ (send global2:horizon()) 10) 179) (send newAct:
                    view(300)
                    loop(0)
                    cel(0)
                    posn(local10 local7)
                    setCycle(End self)
                    init()
                )
 
                (if (< (send newAct:distanceTo(gEgo)) 30)
                    (send newAct:setCel(0))
                    (fish3Actions:changeState(1))
                )
 )
            )
            (case 1
                (
                (if ((send gCast:contains(newAct)))
                    (send newAct:dispose())
                )
 (send (ScriptID(0 4)):setReal(self 3))  )
            )
            (case 2
                ((send global2:setScript(0)) )
            )
        )
    )

)
(instance fishActions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= newAct_2 (Act:new()) = local10 Random(5 304) = local7 Random((+ (send global2:horizon()) 10) 179) (send newAct_2:
                    view(301)
                    loop(0)
                    cel(0)
                    posn(local10 local7)
                    setCycle(End self)
                    init()
                )
 
                (if (< (send newAct_2:distanceTo(gEgo)) 30)
                    (send newAct_2:setCel(0))
                    (fishActions:changeState(1))
                )
 )
            )
            (case 1
                (
                (if ((send gCast:contains(newAct_2)))
                    (send newAct_2:dispose())
                )
 (send (ScriptID(0 4)):setReal(self 3))  )
            )
            (case 2
                ((send global2:setScript(0)) )
            )
        )
    )

)
(instance drown of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 1
                ((send (ScriptID(0 5)):setReal(self 10))  )
            )
            (case 2
                (proc0_10() (send gEgo:
                    view(10)
                    setMotion(0)
                    loop(0)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 3
                ((send gEgo:
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 4
                ((send gEgo:
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 5
                ((send gEgo:hide()) 
                (if (global100)
                    Print(31 18 134 -1 20)
                )(else
                    Print(31 19 134 -1 20)
                )
 = global127 1 )
            )
        )
    )

)
(instance whaleActions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send (ScriptID(0 6)):setReal(self Random(2 8)))  )
            )
            (case 1
                (= newProp_2 (Prop:new()) (whaleMusic:
                    number(36)
                    play()
                )
 (send newProp_2:
                    view(315)
                    cel(0)
                    loop(0)
                    posn(120 67)
                    init()
                    setCycle(End self)
                )
  )
            )
            (case 2
                (
                (if ((send gCast:contains(newProp_2)))
                    (send newProp_2:
                        loop(1)
                        setCycle(Fwd)
                    )
                    (send (ScriptID(0 6)):setReal(self 3))
                )
 )
            )
            (case 3
                (
                (if ((send gCast:contains(newProp_2)))
                    (send newProp_2:
                        loop(2)
                        cel(0)
                        setCycle(End self)
                    )
                )
 )
            )
            (case 4
                (
                (if ((send gCast:contains(newProp_2)))
                    (send newProp_2:dispose())
                )
 (send (ScriptID(0 6)):setReal(self 5))  )
            )
            (case 5
                (proc0_10() (send gEgo:
                    view(84)
                    setMotion(0)
                    cel(0)
                    setLoop(0)
                    setCycle(End self)
                )
  )
            )
            (case 6
                ((send gEgo:hide()) proc0_11() (send global2:newRoom(44))  )
            )
            (case 10
                ((send (ScriptID(0 6)):
                    dispose()
                    delete()
                )
 (send gEgo:
                    view(84)
                    setLoop(1)
                    cel(0)
                    posn(160 130)
                    setCycle(End self)
                    init()
                )
  )
            )
            (case 11
                (Print(31 20) (send gEgo:
                    view(8)
                    setCycle(Fwd)
                    setLoop(-1)
                )
 proc0_11() (send gEgo:script(0)) )
            )
        )
    )

)
(instance sharkActions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= seconds Random(1 5)  )
            )
            (case 1
                ((sharkMusic:
                    number(78)
                    loop(-1)
                    play()
                )
 (send (= newAct_3 (Act:new())):
                    ignoreHorizon()
                    posn(Random(100 200) Random(75 189))
                    view(887)
                    setCycle(Walk)
                    ignoreActors()
                    xStep(5)
                    yStep(4)
                    setMotion(Chase gEgo 10 self)
                    init()
                )
  )
            )
            (case 2
                (proc0_10() (send gEgo:
                    setMotion(0)
                    view(10)
                    loop(0)
                    cel(6)
                    setCycle(End self)
                )
  )
            )
            (case 3
                ((send gEgo:hide()) (sharkMusic:dispose()) 
                (if ((send gCast:contains(newAct_3)))
                    (send newAct_3:setMotion(MoveTo 65516 100))
                )
 = seconds 3  )
            )
            (case 4
                (= global204 0 Print(31 21 134 -1 20) = global127 1 )
            )
        )
    )

)
