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


(local
    local0
    local1
    local2[22]
    gEgoViewer
    newProp
    newProp_2

)
(instance public Room77 of Rm
    (properties
        picture 77
    )

    (method (init)
        = east 78
        = west 73
        = horizon 40
        = global101 0
        Load(rsVIEW 21)
        Load(rsVIEW 69)
        Load(rsVIEW 49)
        Load(rsSCRIPT 991)
        (if (global100)
            = picture 177
        )
        (super:init())
        (self:setRegions(513))
        = newProp (Prop:new())
        = newProp_2 (Prop:new())
        (send newProp:
            view(650)
            loop(2)
            cel(1)
            posn(242 145)
            setPri(0)
            setCycle(Fwd)
            init()
        )
        (send newProp_2:
            view(650)
            loop(4)
            cel(0)
            posn(276 112)
            setPri(0)
            setCycle(Fwd)
            init()
        )
        (switch (gPicture)
            (case east
                ((send gEgo:
                    view(2)
                    posn(301 162)
                    loop(1)
                )
 = local0 10 = local1 20 = global105 12 (User:
                    canControl(1)
                    canInput(1)
                )
  )
            )
            (case west
                ((send gEgo:
                    view(49)
                    setLoop(2)
                    cel(0)
                    posn(32 161)
                    setCycle(Fwd)
                    setScript(egoCrawlOut)
                )
  )
            )
            (default 
                ((send gEgo:
                    view(49)
                    setLoop(2)
                    cel(0)
                    posn(32 161)
                    setCycle(Walk)
                    setScript(egoCrawlOut)
                )
 )
            )
        )
        (send gEgo:init())
        (send gEgo:edgeHit(0))
        = local2[0] 94
        = local2[1] 167
        = local2[2] 112
        = local2[3] 165
        = local2[4] 135
        = local2[5] 162
        = local2[6] 159
        = local2[7] 165
        = local2[8] 186
        = local2[9] 161
        = local2[10] 206
        = local2[11] 165
        = local2[12] 225
        = local2[13] 161
        = local2[14] 244
        = local2[15] 166
        = local2[16] 264
        = local2[17] 163
        = local2[18] 285
        = local2[19] 167
        = local2[20] 301
        = local2[21] 162
        (send global2:setScript(jump))
        = global205 1
    )


    (method (doit)
        (super:doit())
        (if (((== (send gEgo:view()) 5) or (== (send gEgo:view()) 6)) or (== (send gEgo:view()) 7))
            = local0 0
            = local1 0
        )
        (if (((((& (send gEgo:onControl(0)) $4000) and (== (send gEgo:view()) 2)) and (== (send gEgo:script()) 0)) and (< (send gEgo:heading()) 285)) and (> (send gEgo:heading()) 255))
            (send gEgo:setScript(egoCrawlIn))
        )
    )


    (method (dispose)
        DisposeScript(991)
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed()))
            return 1
        )
        return 
            (if (== (send pEvent:type()) 128)
                (if (((Said('look/room') or Said('look/around')) or Said('look/marsh')) or Said('look[<around][/!*]'))
                    Print(77 0)
                )(else
                    (if (Said('look<in/cave'))
                        Print(77 1)
                    )(else
                        (if (Said('look/cave'))
                            Print(77 2)
                        )(else
                            (if (Said('crawl/'))
                                (if ((send gEgo:inRect(40 154 63 170)))
                                    (send gEgo:setScript(egoCrawlIn))
                                )(else
                                    Print(77 3)
                                )
                            )(else
                                (if (Said('hop,hop'))
                                    (jump:changeState(1))
                                )
                            )
                        )
                    )
                )
            )(else
                0
            )
    )

)
(instance egoCrawlOut of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = global105 0 (send gEgo:
                    xStep(1)
                    setMotion(MoveTo 68 161 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    setLoop(0)
                    cel(5)
                    setCycle(Beg self)
                )
  )
            )
            (case 2
                ((send gEgo:
                    view(21)
                    setLoop(0)
                    cel(6)
                    setCycle(Beg self)
                )
  )
            )
            (case 3
                ((send gEgo:
                    view(2)
                    xStep(2)
                    yStep(1)
                    setLoop(-1)
                    setCycle(Walk)
                )
 proc0_11() (send gEgo:setScript(0)) = global105 12 )
            )
        )
    )

)
(instance egoCrawlIn of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() (send gEgo:setMotion(MoveTo 57 162 self))  )
            )
            (case 1
                (= global105 0 (send gEgo:
                    view(21)
                    setLoop(1)
                    cel(0)
                    setCycle(End self)
                )
 (send gEgo:setAvoider(Avoid))  )
            )
            (case 2
                ((send gEgo:
                    view(49)
                    setLoop(1)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 3
                ((send gEgo:
                    setLoop(3)
                    setCycle(Walk)
                    xStep(1)
                    setMotion(MoveTo 32 161 self)
                )
  )
            )
            (case 4
                (proc0_11() (send gEgo:
                    xStep(2)
                    yStep(1)
                    setLoop(-1)
                    setScript(0)
                )
 = global205 1 (send global2:newRoom(73)) )
            )
        )
    )

)
(instance jump of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 1
                (
                (if (== global105 13)
                    Print(77 4)
                    (self:changeState(0))
                )(else
                    (if ((== local0 10) and (== (send gEgo:loop()) 0))
                        proc0_11()
                        = global205 1
                        (send global2:newRoom(78))
                        return 
                    )
                    (if (== local0 0)
                        (if ((not (send gEgo:inRect(87 161 106 172)) or (<> (send gEgo:loop()) 0)) or (<> (send gEgo:view()) 2))
                            (jump:changeState(10))
                        )(else
                            = gEgoViewer (send gEgo:viewer())
                            (send gEgo:viewer(0))
                            proc0_10()
                            (send gEgo:
                                view(69)
                                cel(0)
                                setCycle(End self)
                            )
                        )
                    )(else
                        = gEgoViewer (send gEgo:viewer())
                        (send gEgo:viewer(0))
                        proc0_10()
                        (send gEgo:
                            view(69)
                            cel(0)
                            setCycle(End self)
                        )
                    )
                )
 )
            )
            (case 2
                ((send gEgo:setCycle(CT 1 -1 self))  )
            )
            (case 3
                ((send gEgo:
                    xStep(6)
                    yStep(4)
                )
 
                (if (== (send gEgo:loop()) 0)
                    (send gEgo:
                        setLoop(2)
                        cel(0)
                        setCycle(End)
                    )
                    ++local0
                    = local1 (+ local1 2)
                    (send gEgo:setMotion(JumpTo local2[local1] local2[(+ local1 1)] self))
                )(else
                    (if (== (send gEgo:loop()) 1)
                        (send gEgo:
                            setLoop(3)
                            cel(0)
                            setCycle(End)
                        )
                        --local0
                        = local1 (- local1 2)
                        (send gEgo:setMotion(JumpTo local2[local1] local2[(+ local1 1)] self))
                    )(else
                        (if (== (send gEgo:loop()) 2)
                            (send gEgo:viewer(gEgoViewer))
                            (send gEgo:setMotion(JumpTo (send gEgo:x()) (+ (send gEgo:y()) 6)))
                        )(else
                            (if (== (send gEgo:loop()) 3)
                                (send gEgo:viewer(gEgoViewer))
                                (send gEgo:setMotion(JumpTo (send gEgo:x()) (- (send gEgo:y()) 6)))
                            )
                        )
                    )
                )
 )
            )
            (case 4
                (
                (if (== (send gEgo:loop()) 2)
                    (send gEgo:
                        cel(0)
                        setLoop(-1)
                        loop(4)
                        setCycle(End self)
                    )
                )(else
                    (send gEgo:
                        cel(0)
                        setLoop(-1)
                        loop(5)
                        setCycle(End self)
                    )
                )
 )
            )
            (case 5
                (
                (if (== (send gEgo:loop()) 4)
                    (send gEgo:
                        view(2)
                        loop(0)
                        cel(0)
                        xStep(2)
                        yStep(2)
                    )
                )(else
                    (send gEgo:
                        view(2)
                        loop(1)
                        cel(0)
                        xStep(2)
                        yStep(1)
                    )
                )
 proc0_11() (send gEgo:viewer(gEgoViewer)) (send gEgo:
                    view(2)
                    setCycle(Walk)
                )
  )
            )
            (case 10
                (Print(77 5) )
            )
        )
    )

)
