(version 2)
(include "sci.sh")
(exports
    0 rm500
)
(use "Main")
(use "FPRoom")
(use "Scaler")
(use "PolyPath")
(use "Polygon")
(use "CueObj")
(use "Door")
(use "n958")
(use "Cycle")
(use "View")
(use "Obj")
(script 500)


(local
    local0
    local1
    hopSinghCycleSpeed

)
(instance public rm500 of FPRoom
    (properties
        noun 16
        picture 500
        style $000a
        north 670
        south 310
    )

    (method (init)
        proc958_0(132 502 501)
        proc958_0(128 501 500 124)
        (send gEgo:
            init()
            setScale(Scaler 79 50 189 35)
            normalize()
        )
        (switch (gGNumber)
            (case south
                (send gEgo:x(160))
                (send gGame:handsOn())
            )
            (case 230
                (send global2:setScript(sEnterFrom230))
            )
            (case 235
                (send global2:setScript(sEnterFrom230))
            )
            (case 670
                (send gEgo:loop(2))
                (send gEgo:edgeHit(0))
            )
            (case 680
                (send gGame:handsOn())
            )
            (default 
                (send gEgo:
                    x(160)
                    y(160)
                )
                (send gGame:handsOn())
            )
        )
        (super:init(self))
        (send global2:addObstacle((send ((Polygon:new())):
                type(2)
                init(0 0 319 0 319 189 183 189 183 182 211 182 211 164 238 164 238 143 295 143 295 132 240 109 206 109 206 74 199 74 199 110 194 110 194 114 154 114 154 112 146 112 146 105 96 105 96 108 87 108 87 113 70 113 70 118 45 118 45 91 58 47 58 31 14 31 14 34 53 34 53 48 50 48 30 94 30 118 23 118 23 179 138 179 138 189 0 189)
                yourself()
            )
))
        (if (proc0_2(1) or proc0_2(29))
            = local1 1
        )(else
            (if (not proc0_2(14))
                (hopSingh:
                    init()
                    setScript(sSinghShift)
                )
            )
        )
        (if (not proc0_2(1) and (< global119 19))
            (send gGameMusic1:
                number(501)
                loop(-1)
                play()
            )
        )
        (if ((> global120 2) and not proc0_2(14))
            (pie:
                init()
                approachVerbs(4)
                setCycle(Fwd)
            )
        )
        (if (not proc0_2(30))
            (icepick:
                init()
                stopUpd()
                approachVerbs(1 4)
            )
        )
        (if (not proc0_2(65))
            (elixir:
                init()
                stopUpd()
                approachVerbs(1 4)
            )
        )
        (saloonBackDoor:
            init()
            stopUpd()
        )
        (barrel:init())
        (momsWindow:init())
        (roomsSign:init())
        (roofTop:
            init()
            setOnMeCheck(1 4)
        )
        (elixirWagon:
            init()
            setOnMeCheck(1 8)
        )
        (trunks:
            init()
            setOnMeCheck(1 16)
        )
        (tree:
            init()
            setOnMeCheck(1 32)
        )
        (stairs:
            init()
            setOnMeCheck(1 64)
        )
        (topSign:
            init()
            setOnMeCheck(1 128)
        )
        (bottomSign:
            init()
            setOnMeCheck(1 256)
        )
        (hotel:
            init()
            setOnMeCheck(1 512)
        )
        (poster:
            init()
            setOnMeCheck(1 1024)
        )
        (leaflet:
            init()
            setOnMeCheck(1 2048)
        )
        (moms:
            init()
            setOnMeCheck(1 4096)
        )
        (saloon:
            init()
            setOnMeCheck(1 8192)
        )
        (if (proc0_2(52))
            (dummyCredits:
                init()
                setScript(ScriptID(32 0))
            )
        )
    )


    (method (doit)
        (var temp0[20])
        (super:doit())
        (if (((not proc0_2(14) and local1) and not proc0_2(29)) and not proc0_2(1))
            (hopSingh:
                init()
                setScript(sSinghShift)
            )
            = local1 0
        )
        (if (script)
        )(else
            (if ((send gEgo:inRect(18 100 60 114)))
                (send global2:setScript(sClimbStairs 0 1))
            )(else
                (if ((send gEgo:inRect(36 49 62 56)))
                    (send global2:setScript(sClimbStairs 0 2))
                )(else
                    (if (proc0_1(gEgo 2))
                        (send global2:setScript(sExitTo230))
                    )
                )
            )
        )
    )


    (method (dispose)
        (if (<> global119 14)
            (send gGameMusic1:fade(0 30 12 1))
        )
        DisposeScript(32)
        (super:dispose())
    )


    (method (newRoom newRoomNumber)
        (if ((== newRoomNumber 230) and proc999_5(global119 8 9 20 22))
            = newRoomNumber 235
        )
        (super:newRoom(newRoomNumber))
    )

)
(instance sExitTo230 of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gGame:handsOff())
                (send gEgo:
                    setPri(0)
                    setMotion(PolyPath 60 33 self)
                )
            )
            (case 1
                = cycles 2
            )
            (case 2
                (send gEgo:setHeading(270 self))
            )
            (case 3
                = cycles 2
            )
            (case 4
                (send gEgo:setMotion(MoveTo 40 33 self))
            )
            (case 5
                (send gEgo:setPri(-1))
                (send global2:newRoom(230))
            )
        )
    )

)
(instance sEnterFrom230 of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gGame:handsOff())
                (send gEgo:
                    posn(40 33)
                    setPri(0)
                )
                = cycles 2
            )
            (case 1
                (send gEgo:setMotion(MoveTo 60 33 self))
            )
            (case 2
                = cycles 2
            )
            (case 3
                (send gEgo:setHeading(200 self))
            )
            (case 4
                = cycles 2
            )
            (case 5
                (send gEgo:
                    setLoop(5)
                    setPri(-1)
                    setLoop(-1)
                    setMotion(MoveTo 57 48 self)
                )
            )
            (case 6
                (if (HaveMouse())
                    (self:setScript(sClimbStairs self 2))
                )(else
                    = cycles 2
                )
            )
            (case 7
                (send gGame:handsOn())
                (self:dispose())
            )
        )
    )

)
(instance sClimbStairs of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gGame:handsOff())
                (switch (register)
                    (case 1
                        (send gEgo:
                            setLoop(3)
                            setMotion(MoveTo 42 92 self)
                        )
                    )
                    (case 2
                        ++state
                        (send gEgo:
                            setPri(-1)
                            setMotion(PolyPath 36 115 self)
                        )
                    )
                )
            )
            (case 1
                (send gEgo:setMotion(PolyPath 57 48 self))
            )
            (case 2
                (if ((== register 1) and HaveMouse())
                    = next sExitTo230
                )(else
                    (send gGame:handsOn())
                    (send gEgo:setLoop(-1))
                )
                (self:dispose())
            )
        )
    )

)
(instance sStopFreddy of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gGame:handsOff())
                (send gFpMessager:say(17 4 1))
                = cycles 2
            )
            (case 1
                (send gEgo:
                    view(124)
                    setLoop(2)
                    setCel(0)
                    setCycle(CT 6 1 self)
                )
                = hopSinghCycleSpeed (hopSingh:cycleSpeed)
                (hopSingh:
                    setLoop(0)
                    setCel(0)
                    setCycle(0)
                    setSpeed(10)
                    posn(138 92)
                )
            )
            (case 2
                (hopSingh:setCycle(End self))
                (send gGameMusic1:
                    number(502)
                    loop(1)
                    play(self)
                )
            )
            (case 3
                0
            )
            (case 4
                (send gGameMusic1:
                    number(501)
                    loop(-1)
                    play()
                )
                (send gEgo:setCel(0))
                = seconds 3
            )
            (case 5
                (send gEgo:
                    normalize()
                    loop(0)
                )
                (send gFpMessager:say(17 4 2))
                (hopSingh:
                    setSpeed(hopSinghCycleSpeed)
                    setScript(sSinghShift)
                )
                (send gGame:handsOn())
                (self:dispose())
            )
        )
    )

)
(instance sGetPie of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gGame:handsOff())
                (send gEgo:
                    view(124)
                    setLoop(2)
                    setCel(0)
                    setCycle(CT 6 1 self)
                )
            )
            (case 1
                (pie:dispose())
                (send gEgo:setCycle(End self))
            )
            (case 2
                (send gEgo:
                    normalize()
                    loop(0)
                )
                (send gEgo:get(43 pie))
                proc0_3(14)
                (send gGame:points(1))
                (send gGame:handsOn())
                (self:dispose())
            )
        )
    )

)
(instance sSinghShift of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = local0 
                    (if (not Random(0 2))
                        138
                    )(else
                        151
                    )
                (hopSingh:
                    setLoop(1)
                    setCycle(Fwd)
                    xStep(2)
                    setMotion(MoveTo local0 (hopSingh:y) self)
                )
            )
            (case 1
                (if (== (hopSingh:loop) 0)
                    (hopSingh:
                        setLoop(1)
                        setMotion(MoveTo 151 (hopSingh:y) self)
                    )
                    --state
                )(else
                    (if (== (hopSingh:x) 138)
                        (hopSingh:
                            setLoop(0)
                            setCel(0)
                        )
                        --state
                        = seconds Random(2 3)
                    )(else
                        = seconds Random(3 7)
                    )
                )
            )
            (case 2
                (hopSingh:
                    setLoop(2)
                    setMotion(MoveTo 122 (hopSingh:y) self)
                )
            )
            (case 3
                = seconds Random(3 7)
            )
            (case 4
                (self:changeState(0))
            )
            (case 5
                (self:dispose())
            )
        )
    )

)
(instance saloonBackDoor of Door
    (properties
        x 211
        y 104
        noun 3
        approachX 203
        approachY 111
        view 500
        loop 1
        entranceTo 670
        openSnd 2146
        closeSnd 2147
        openVerb 4
        moveToX 203
        moveToY 100
        enterType 0
        exitType 0
    )

    (method (createPoly)
        (super:createPoly(187 108 187 102 219 102 219 108))
    )

)
(instance pie of Prop
    (properties
        x 137
        y 98
        z 10
        noun 17
        approachX 120
        approachY 114
        view 500
        signal $4000
        cycleSpeed 12
        detailLevel 2
    )

    (method (doVerb theVerb)
        (switch (theVerb)
            (case 4
                (if (proc0_2(29))
                    (send global2:setScript(sGetPie))
                )(else
                    (hopSingh:
                        setScript(0)
                        setMotion(0)
                    )
                    (send global2:setScript(sStopFreddy))
                )
            )
            (default 
                (super:doVerb(theVerb))
            )
        )
    )

)
(instance hopSingh of Actor
    (properties
        x 124
        y 96
        noun 19
        view 501
        priority 1
        signal $4010
    )
)
(instance dummyCredits of Prop
    (properties
        x -10
        y -10
        view 996
    )
)
(instance icepick of View
    (properties
        x 176
        y 87
        noun 18
        approachX 162
        approachY 119
        view 500
        loop 2
        signal $4000
    )

    (method (doVerb theVerb)
        (switch (theVerb)
            (case 4
                (send gEgo:get(24 self 2 self))
                proc0_3(30)
                (send gGame:points(1))
            )
            (default 
                (super:doVerb(theVerb))
            )
        )
    )

)
(instance elixir of View
    (properties
        x 240
        y 172
        z 5
        noun 20
        approachX 195
        approachY 176
        view 500
        loop 3
        priority 15
        signal $4010
    )

    (method (doVerb theVerb)
        (switch (theVerb)
            (case 4
                (send gEgo:get(17 self 2 self))
                proc0_3(65)
                (send gGame:points(1))
            )
            (default 
                (super:doVerb(theVerb))
            )
        )
    )

)
(instance barrel of Feature
    (properties
        x 177
        y 103
        noun 21
        nsTop 97
        nsLeft 166
        nsBottom 110
        nsRight 189
        sightAngle 40
    )
)
(instance momsWindow of Feature
    (properties
        x 137
        y 74
        noun 2
        nsTop 59
        nsLeft 127
        nsBottom 90
        nsRight 147
    )
)
(instance roomsSign of Feature
    (properties
        x 27
        y 11
        noun 1
        nsTop 3
        nsBottom 19
        nsRight 55
    )
)
(instance roofTop of Feature
    (properties
        x 57
        y 171
        noun 4
        onMeCheck $0004
    )
)
(instance elixirWagon of Feature
    (properties
        x 269
        y 152
        noun 5
        onMeCheck $0008
    )
)
(instance trunks of Feature
    (properties
        x 271
        y 104
        noun 6
        onMeCheck $0010
    )
)
(instance tree of Feature
    (properties
        x 315
        y 56
        noun 7
        onMeCheck $0020
    )
)
(instance stairs of Feature
    (properties
        x 48
        y 64
        noun 8
        onMeCheck $0040
    )
)
(instance topSign of Feature
    (properties
        x 13
        y 34
        noun 9
        onMeCheck $0080
    )
)
(instance bottomSign of Feature
    (properties
        x 9
        y 54
        noun 10
        onMeCheck $0100
    )
)
(instance hotel of Feature
    (properties
        x 29
        y 51
        noun 11
        onMeCheck $0200
    )
)
(instance poster of Feature
    (properties
        x 100
        y 79
        noun 12
        onMeCheck $0400
    )
)
(instance leaflet of Feature
    (properties
        x 85
        y 81
        noun 13
        onMeCheck $0800
    )
)
(instance moms of Feature
    (properties
        x 120
        y 100
        noun 14
        onMeCheck $1000
    )
)
(instance saloon of Feature
    (properties
        x 227
        y 72
        noun 15
        onMeCheck $2000
    )
)
