(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "rssScript")
(use "SQRoom")
(use "Polygon")
(use "Class_950_0")
(use "n958")
(use "Cycle")
(use "PicView")
(use "Obj")
(script 315)


(local
    local0[14] = (59 0 118 52 120 79 96 91 51 99 0 101 )
    local14[34] = (0 119 67 119 72 125 116 125 119 129 161 129 220 119 251 109 251 102 267 94 277 89 240 72 192 15 192 0 319 0 319 189 0 189 )

)
(instance public rm315 of SQRoom
    (properties
        picture 315
        horizon 15
        north 305
        west 310
    )

    (method (init)
        proc958_0(128 0 303 300)
        Load(rsSOUND 52)
        (if (> (butte:policeLanded) 0)
            Load(rsVIEW 305)
            Load(rsPIC 300)
        )(else
            proc958_0(128 7 5)
        )
        (self:
            setRegions(703)
            setFeatures(theRoom)
        )
        (switch (global12)
            (case north
                proc0_3()
                (butte:entered315((+ (butte:entered315) 1)))
                (self:
                    setScript(enterScript)
                    style(42)
                )
            )
            (case west
                proc0_3()
                (self:style(41))
            )
            (default 
                proc0_3()
                (send gEgo:
                    view(0)
                    posn(155 110)
                )
            )
        )
        (poly1:
            points(@local0)
            size(7)
        )
        (poly2:
            points(@local14)
            size(17)
        )
        (self:addObstacle(poly1 poly2))
        (send gEgo:
            setPri(8)
            init()
        )
        (super:init())
        (if ((== (butte:curPolice1Room) 315) or (== (butte:curPolice2Room) 315))
            (butte:junctioned(1))
            (send (ScriptID(703 4)):
                posn(150 110)
                init()
                setScript(copEnters)
            )
        )(else
            (butte:junctioned(0))
        )
    )


    (method (doit)
        (var temp0)
        (if (script)
        )(else
            (if ((== script fallScript) and (== (send gEgo:edgeHit) 3))
                0
            )(else
                (if (== (send gEgo:edgeHit) 1)
                    proc0_2()
                    (self:setScript(exitScript))
                )
            )
        )
        (super:doit())
        = temp0 (send gEgo:onControl(1))
        (if (script)
        )(else
            (if ((butte:junctioned) and not (send (ScriptID(703 4)):script))
                (if (== (butte:oldPoliceRoom) 305)
                    (send (ScriptID(703 4)):posn(150 65531))
                )(else
                    (if (== (butte:oldPoliceRoom) 310)
                        (send (ScriptID(703 4)):posn(65531 110))
                    )
                )
                (send (ScriptID(703 4)):init())
                (send (ScriptID(703 4)):setScript(copEnters))
            )(else
                (if ((((((& temp0 $0004) or (& temp0 $0010)) or (& temp0 $0040)) or (& temp0 $0080)) or (& temp0 $0100)) or (& temp0 $0200))
                    proc0_2()
                    (self:setScript(fallScript 0 temp0))
                )(else
                    (if ((((butte:sawShadow) and (< 48 (send gEgo:y))) and (< (send gEgo:y) 51)) and not proc0_6(32))
                        (butte:beenCaptured(1))
                        (self:setScript(pteraDives))
                    )
                )
            )
        )
    )

)
(instance fallScript of Script
    (properties)

    (method (changeState newState)
        (var temp0[2])
        (switch (= state newState)
            (case 0
                (if (& register $0004)
                    (send gEgo:setPri(1))
                )(else
                    (if (& register $0010)
                        (send gEgo:setPri(6))
                    )(else
                        (send gEgo:setPri(3))
                    )
                )
                (send global2:setScript(ScriptID(703 1)))
                (self:dispose())
            )
        )
    )

)
(instance enterScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gEgo:
                    x(
                        (if (< (send gEgo:x) 112)
                            112
                        )(else
                            (if (> (send gEgo:x) 214)
                                214
                            )(else
                                (send gEgo:x)
                            )
                        )
)
                    y(50)
                )
                = cycles 1
            )
            (case 1
                proc0_3()
                (send client:setScript(0))
            )
        )
    )

)
(instance exitScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gEgo:setMotion(MoveTo (send gEgo:x) 65534 self))
            )
            (case 1
                (send global2:newRoom((send global2:north)))
            )
        )
    )

)
(instance ptera of Actor
    (properties
        x 220
        y 65496
        lookStr "I don't know what that is but I see the need for a bunion pad or two. Maybe some pumice here and there."
        yStep 15
        view 303
        priority 15
        signal 28688
        xStep 35
    )
)
(instance pteraDives of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (ptera:
                    x(+ (send gEgo:x) 40)
                    init()
                    setMotion(pteraChase gEgo 5 self)
                )
            )
            (case 1
                (send gLongSong:
                    number(52)
                    loop(-1)
                    vol(127)
                    flags(1)
                    playBed()
                )
                proc0_2()
                (send gEgo:hide())
                (ptera:
                    x(+ (ptera:x) 28)
                    setCel(1)
                )
                = cycles 2
            )
            (case 2
                (ptera:
                    x(- (ptera:x) 35)
                    setCel(2)
                )
                = cycles 2
            )
            (case 3
                (ptera:
                    xStep(10)
                    setMotion(MoveTo 65516 65476 self)
                )
            )
            (case 4
                (ptera:dispose())
                (send global2:newRoom(298))
                (send client:setScript(0))
            )
        )
    )

)
(class pteraChase of Motion
    (properties
        client 0
        caller 0
        x 0
        y 0
        dx 0
        dy 0
        {b-moveCnt} 0
        {b-i1} 0
        {b-i2} 0
        {b-di} 0
        {b-xAxis} 0
        {b-incr} 0
        completed 0
        xLast 0
        yLast 0
        who 0
        distance 0
    )

    (method (init theClient theWho theDistance theCaller)
        (if (>= paramTotal 1)
            = client theClient
            (if (>= paramTotal 2)
                = who theWho
                (if (>= paramTotal 3)
                    = distance theDistance
                    (if (>= paramTotal 4)
                        = caller theCaller
                    )
                )
            )
        )
        (super:init(client (send who:x) (- (send who:y) 55) caller))
    )


    (method (doit)
        (if ((self:onTarget()))
            (self:moveDone())
        )(else
            (super:doit())
            (if (== {b-moveCnt} 0)
                (super:init(client (send who:x) (- (send who:y) 55) caller))
            )
        )
    )


    (method (onTarget)
        return 
            (if (<= Abs((- (send client:x) (send who:x))) distance)
                <= Abs((- (send client:y) (- (send who:y) 55))) distance
            )(else
                0
            )
    )

)
(instance copEnters of Script
    (properties)

    (method (doit)
        (if (not (send global2:script) and (== state 0))
            (self:cue())
        )
        (if ((< (send (ScriptID(703 4)):distanceTo(gEgo)) 80) and not (send global2:script))
            (send (ScriptID(703 4)):setScript(ScriptID(703 5)))
            (self:dispose())
        )
        (super:doit())
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                0
            )
            (case 1
                (send (ScriptID(703 4)):
                    setCycle(Walk)
                    setMotion(MoveTo 150 110 self)
                )
            )
            (case 2
                (send (ScriptID(703 4)):setMotion(MoveTo (send gEgo:x) (send gEgo:y) self))
            )
        )
    )

)
(instance poly1 of Polygon
    (properties)
)
(instance poly2 of Polygon
    (properties)
)
(instance theRoom of Feature
    (properties
        nsBottom 200
        nsRight 320
        description "buttes"
        lookStr "The hot Estros sun and the seductive curves of the butte are strangely exciting.  You've descended to the \"plateau phase\" of your journey.  The plateau continues to the west, while the rocky layers climax in a makeshift staircase leading up to the next plateau.  In the distance, you can see the beautiful, tranquil Sea of Estros."
    )

    (method (doVerb param1)
        (switch (param1)
            (case 4
                (send (ScriptID(703 6)):doVerb(param1))
            )
            (case 1
                Print("The hot Estros sun and the seductive curves of the butte are strangely exciting.  You've descended to the \"plateau phase\" of your journey.  The plateau continues to the west, while the rocky layers climax in a makeshift staircase leading up to the next plateau.  In the distance, you can see the beautiful, tranquil Sea of Estros.")
            )
            (default 
                (super:doVerb())
            )
        )
    )

)
