(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 300)



(instance public rm300 of SQRoom
    (properties
        picture 300
        east 305
        south 310
        west 299
    )

    (method (init)
        proc958_0(128 0 300)
        (if (not (butte:sawShadow))
            Load(rsVIEW 301)
        )
        (self:
            setRegions(703)
            setFeatures(theStairs theRoom)
        )
        (send gEgo:setPri(8))
        (switch (gWest)
            (case south
                proc0_3()
                (self:
                    style(43)
                    setScript(enterScript)
                )
            )
            (case east
                proc0_3()
                (self:style(40))
                (send gEgo:
                    y(
                        (if (< (send gEgo:y) 67)
                            67
                        )(else
                            (if (> (send gEgo:y) 88)
                                88
                            )(else
                                (send gEgo:y)
                            )
                        )
)
                    setHeading(270 self)
                )
            )
            (case west
                proc0_2()
                (self:
                    style(41)
                    setScript(enterScript)
                )
            )
            (default 
                proc0_3()
                (send gEgo:
                    view(0)
                    illegalBits(0)
                    posn(150 79)
                )
            )
        )
        (send global2:addObstacle((send ((Polygon:new())):
                type(1)
                init(0 0 319 0 319 65 146 65 136 45 40 65 40 82 23 91 0 92)
                yourself()
            )
 (send ((Polygon:new())):
                type(1)
                init(319 189 286 189 239 152 221 137 198 133 191 124 176 121 154 95 162 88 319 88)
                yourself()
            )
 (send ((Polygon:new())):
                type(1)
                init(0 189 0 103 16 96 49 94 61 99 87 99 105 109 98 124 104 133 95 151 129 189)
                yourself()
            )
))
        (send gEgo:init())
        (super:init())
        (if (not (butte:onLedgeFlag))
            (send gEgo:illegalBits(0))
        )
        (if (< (butte:policeLanded) 0)
            proc958_0(128 305 7 5)
            (send global2:addObstacle((send ((Polygon:new())):
                    type(2)
                    init(144 51 163 80 115 92 62 97 43 87 46 70)
                    yourself()
                )
))
            (policePod:
                cel(10)
                init()
                stopUpd()
            )
            (if ((== (butte:curPolice1Room) 300) or (== (butte:curPolice2Room) 300))
                (butte:junctioned(1))
                (send (ScriptID(703 4)):
                    posn(147 90)
                    init()
                    setScript(copEnters)
                )
            )(else
                (butte:junctioned(0))
            )
        )(else
            (self:addObstacle((send ((Polygon:new())):
                    type(2)
                    init(130 52 143 68 93 78 83 83 59 84 45 80 46 70)
                    yourself()
                )
))
        )
    )


    (method (doit)
        (var temp0)
        (if (script)
            0
        )(else
            (if (== (send gEgo:edgeHit) 3)
                proc0_2()
                (self:setScript(exitSouthScript))
            )(else
                (if (== (send gEgo:edgeHit) 2)
                    proc0_2()
                    (self:setScript(exitEastScript))
                )
            )
        )
        (super:doit())
        = temp0 (send gEgo:onControl(1))
        (if (script)
        )(else
            (if (not (butte:sawShadow) and (& temp0 $0800))
                (if (IsObject(policePod))
                    (policePod:setPri(15))
                )
                (send gEgo:setPri(15))
                (butte:sawShadow((+ (butte:sawShadow) 1)))
                proc0_2()
                (send global2:overlay(301 100))
                (self:setScript(shadowScript))
            )(else
                (if ((butte:junctioned) and not (send (ScriptID(703 4)):script))
                    (if (== (butte:oldPoliceRoom) 305)
                        (send (ScriptID(703 4)):posn(330 76))
                    )(else
                        (if (== (butte:oldPoliceRoom) 310)
                            (send (ScriptID(703 4)):posn(179 250))
                        )(else
                            (if (== (butte:oldPoliceRoom) 299)
                                (send (ScriptID(703 4)):posn(0 95))
                            )
                        )
                    )
                    (send (ScriptID(703 4)):init())
                    (send (ScriptID(703 4)):setScript(copEnters))
                )(else
                    (if ((((((& temp0 $0004) or (& temp0 $0200)) or (& temp0 $0010)) or (& temp0 $2000)) or ((& temp0 $0008) and not (butte:onLedgeFlag))) or ((& temp0 $0020) and (butte:onLedgeFlag)))
                        proc0_2()
                        (self:setScript(fallScript 0 temp0))
                    )
                )
            )
        )
    )

)
(instance fallScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if (& register $0200)
                    0
                )(else
                    (if (& register $0010)
                        (send gEgo:setPri(4))
                    )(else
                        (if (& register $0008)
                            (send gEgo:setPri(4))
                        )(else
                            (if (& register $0020)
                                (send gEgo:setPri(13))
                            )(else
                                (if (& register $2000)
                                    (send gEgo:
                                        x(
                                            (if (> (send gEgo:x) 150)
                                                + (send gEgo:x) 7
                                            )(else
                                                - (send gEgo:x) 7
                                            )
)
                                        setPri(4)
                                    )
                                )(else
                                    (if (& register $0004)
                                        (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
                (if (== gWest 299)
                    (send gEgo:
                        posn(8 94)
                        setMotion(MoveTo 37 94 self)
                    )
                )(else
                    (if ((butte:onLedgeFlag))
                        (send gEgo:
                            illegalBits(32832)
                            setPri(15)
                        )
                        (self:cue())
                    )(else
                        (self:cue())
                    )
                )
            )
            (case 1
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance exitSouthScript of Script
    (properties)

    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                (if ((butte:onLedgeFlag))
                    (send global2:newRoom((send global2:south)))
                )(else
                    (send gEgo:setMotion(MoveTo 180 250 self))
                )
            )
            (case 1
                (send global2:newRoom((send global2:south)))
            )
        )
    )

)
(instance exitEastScript of Script
    (properties)

    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                (send gEgo:
                    setHeading(90)
                    setMotion(MoveTo 335 (send gEgo:y) self)
                )
            )
            (case 1
                (send global2:newRoom((send global2:east)))
            )
        )
    )

)
(instance policePod of View
    (properties
        x 149
        y 83
        description "time pod"
        lookStr "What's this? It looks like we've got company here and it's probably not native. Must be those armed tough guys you met on Magmetheus."
        view 305
        loop 1
        priority 5
        signal 16400
    )

    (method (doVerb param1)
        (switch (param1)
            (case 2
                Print("You can't do that.")
            )
            (default 
                (super:doVerb(param1))
            )
        )
    )

)
(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 147 90 self)
                )
            )
            (case 2
                (send (ScriptID(703 4)):setMotion(MoveTo (send gEgo:x) (send gEgo:y) self))
            )
        )
    )

)
(instance ptera of Actor
    (properties
        x 200
        y 68
        view 301
        priority 6
        signal 16400
    )
)
(instance shadowScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gIconBar:disable())
                (send gEgo:setHeading(44))
                (ptera:
                    illegalBits(0)
                    init()
                    cycleSpeed(1)
                    setMotion(MoveTo 257 97 self)
                )
            )
            (case 1
                (send gEgo:setHeading(90))
                (ptera:setMotion(MoveTo 314 126 self))
            )
            (case 2
                (ptera:posn((+ (ptera:x) 50) (ptera:y)))
                (ptera:dispose())
                (send gEgo:setHeading(136))
                = cycles 2
            )
            (case 3
                (send global2:drawPic(300 100))
                = cycles 1
            )
            (case 4
                Print("Whoaahhh! What was that?!")
                (if (IsObject(policePod))
                    (policePod:setPri(5))
                )
                (send gEgo:setPri(8))
                = seconds 1
            )
            (case 5
                (if (gTheNewDialog)
                    (send gTheNewDialog:dispose())
                )
                (send gIconBar:enable())
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance theStairs of Feature
    (properties
        nsBottom 200
        nsRight 320
        description "stairs"
        onMeCheck 16384
        lookStr "Sedimentary layers of rock form a stairway which winds its way down below."
    )
)
(instance theRoom of Feature
    (properties
        nsBottom 200
        nsRight 320
        description "buttes"
        lookStr "From way up here, the view is simply gorges and steep rocky hills.  The giant sun of Estros mercilessly pounds sand all around you, until you can feel the heat through the soles of your boots."
    )

    (method (doVerb param1)
        (switch (param1)
            (case 4
                (send (ScriptID(703 6)):doVerb(param1))
            )
            (case 1
                Print("From way up here, the view is simply gorges and steep rocky hills.  The giant sun of Estros mercilessly pounds sand all around you, until you can feel the heat through the soles of your boots.")
            )
            (default 
                (super:doVerb())
            )
        )
    )

)
