(version 2)
(include "sci.sh")
(exports
    0 rm240
)
(use "Main")
(use "OccasionalCycle")
(use "FPRoom")
(use "Scaler")
(use "Polygon")
(use "CueObj")
(use "Door")
(use "n958")
(use "Cycle")
(use "View")
(use "Obj")
(script 240)


(local
    local0
    local1 =     1
    local2 =     1
    local3 =     1
    gEgoMoveSpeed

)
(instance public rm240 of FPRoom
    (properties
        noun 1
        picture 240
        style $0064
        horizon 40
        north 310
        east 250
        west 230
    )

    (method (init)
        (if (proc0_2(59))
            (self:setRegions(90))
        )
        (if (== global119 22)
            (self:setRegions(91))
        )
        (send gEgo:
            init()
            setScale(Scaler 100 50 175 95)
            normalize()
        )
        (switch (gGNumber)
            (case west
                = style 12
                (send gGame:handsOn())
            )
            (case 235
                = style 12
                (send gGame:handsOn())
            )
            (case east
                = style 11
                (send gGame:handsOn())
            )
            (case north
                (send gEgo:
                    x(50)
                    y(160)
                )
                (send gGame:handsOn())
            )
            (case 150
                (send gEgo:
                    x(160)
                    y(160)
                )
                (send gGame:handsOn())
            )
            (case 650
                = local3 1
            )
            (case 640
                = local3 1
            )
            (case 680
                (send gGame:handsOn())
            )
            (case 26
                (if (proc0_2(80))
                    = global120 4
                    = global119 20
                    (send gEgo:
                        posn(242 142)
                        setHeading(180)
                    )
                    proc0_4(80)
                    (send gGame:handsOn())
                )(else
                    = local3 0
                    proc958_0(130 1814)
                    (send global2:setScript(sSepiaStart))
                )
            )
            (default 
                (send gEgo:
                    x(160)
                    y(160)
                )
                (send gGame:handsOn())
            )
        )
        (if (== local3 0)
            0
        )(else
            (if (== global119 14)
                0
            )(else
                (if (proc999_5(gGNumber 650))
                    (send gGameMusic2:
                        number(640)
                        flags(1)
                        loop(-1)
                        play()
                        setVol(0)
                    )
                )(else
                    (if (proc999_5(gGNumber 640 26))
                        (send gGameMusic1:
                            number(652)
                            flags(1)
                            loop(-1)
                            play()
                            setVol(0)
                        )
                    )(else
                        (send gGameMusic1:
                            number(652)
                            flags(1)
                            loop(-1)
                            play()
                            setVol(
                                (if (proc999_5(gGNumber 230 310))
                                    80
                                )(else
                                    0
                                )
)
                        )
                        (send gGameMusic2:
                            number(640)
                            flags(1)
                            loop(-1)
                            play()
                            setVol(
                                (if (== gGNumber 250)
                                    80
                                )(else
                                    0
                                )
)
                        )
                    )
                )
            )
        )
        (super:init())
        (send global2:addObstacle((send ((Polygon:new())):
                type(2)
                init(319 102 316 102 316 81 311 81 311 102 274 102 272 109 263 109 257 104 217 104 217 106 143 106 135 94 135 79 129 79 129 94 115 107 99 107 95 98 59 98 48 56 58 50 49 29 25 29 23 109 0 111 0 0 319 0)
                yourself()
            )
 (send ((Polygon:new())):
                type(2)
                init(0 176 319 176 319 189 0 189)
                yourself()
            )
 (send ((Polygon:new())):
                type(2)
                init(27 110 27 122 6 122 7 113)
                yourself()
            )
))
        (if (proc0_2(1))
            (barberDoor:
                init()
                locked(1)
            )
            (storeDoor:
                init()
                locked(1)
            )
        )(else
            (barberDoor:init())
            (if ((<> global119 22) and (>= (send gGame:detailLevel()) 2))
                (shrub1:
                    init()
                    hide()
                    setScript(sBreezeShrubs)
                )
                (shrub2:
                    init()
                    hide()
                )
                (bucket:
                    init()
                    hide()
                    setScript(sWaterBucket)
                )
                (barberpole:
                    init()
                    cycleSpeed(14)
                    setCycle(Fwd)
                )
            )
            (if (>= global119 20)
                (storeDoorClosed:
                    init()
                    approachVerbs(4)
                )
            )(else
                (storeDoor:init())
            )
        )
        (if (== global119 22)
            (send gNarrator:modeless(1))
            (cowboy1:
                setLoop(Random(0 1))
                setScale(Scaler 100 50 175 95)
                setCycle(OccasionalCycle 1 10 30 2 6)
                setScript(sRowdysKill)
                init()
            )
            (cowboy2:
                setLoop(Random(2 3))
                setScale(-1 cowboy1)
                setCycle(OccasionalCycle 1 10 30 2 6)
                init()
            )
            (if ((> global87 6) and (> (send gGame:detailLevel()) 3))
                (cowboy3:
                    setLoop(Random(4 5))
                    setScale(-1 cowboy1)
                    setCycle(OccasionalCycle 1 10 30 2 6)
                    init()
                )
            )
            (if ((> global87 13) and (> (send gGame:detailLevel()) 1))
                (cowboy4:
                    setLoop(Random(6 7))
                    setScale(-1 cowboy1)
                    setCycle(OccasionalCycle 1 10 30 2 6)
                    init()
                )
            )
        )
        (store:
            init()
            setOnMeCheck(1 128)
        )
        (postOffice:
            init()
            setOnMeCheck(1 256)
        )
        (barberShop:
            init()
            setOnMeCheck(1 512)
        )
        (clutter:
            init()
            setOnMeCheck(1 1024)
        )
        (storeWindow:
            init()
            setOnMeCheck(26505)
        )
        (postWindow:
            init()
            setOnMeCheck(26505)
        )
        (barberWindow:
            init()
            setOnMeCheck(26505)
        )
        (storeSign:
            init()
            setOnMeCheck(26505)
        )
        (postSign:
            init()
            setOnMeCheck(26505)
        )
        (barberSign:
            init()
            setOnMeCheck(26505)
        )
        (hotel:
            init()
            setOnMeCheck(26505)
        )
        (wagon:
            init()
            setOnMeCheck(26505)
        )
        (postDoor:
            init()
            setOnMeCheck(26505)
            approachVerbs(4 9)
        )
        (if (proc0_2(52))
            (dummyCredits:
                init()
                setScript(ScriptID(32 0))
            )
        )
    )


    (method (doit)
        (var temp0, temp1, temp2[2])
        (super:doit())
        (if (local0 and (== PalVary(pvGET_CURRENT_STEP) 0))
            (sSepiaStart:cue())
            = local0 0
        )(else
            (if (== global119 14)
                0
            )(else
                (if (local3 and (<= (send gEgo:x) 219))
                    (if (> (send gGameMusic2:vol) 0)
                        (send gGameMusic2:setVol(0))
                    )
                    = temp0 GetDistance((send gEgo:x) (send gEgo:y) 219 (send gEgo:y))
                    (if (< temp0 20)
                        = temp0 20
                    )(else
                        (if (> temp0 80)
                            = temp0 80
                        )
                    )
                    (send gGameMusic1:setVol(temp0))
                )(else
                    (if (local3 and (>= (send gEgo:x) 220))
                        (if (> (send gGameMusic1:vol) 0)
                            (send gGameMusic1:setVol(0))
                        )
                        = temp1 GetDistance((send gEgo:x) (send gEgo:y) 220 (send gEgo:y))
                        (if (< temp1 20)
                            = temp1 20
                        )(else
                            (if (> temp1 80)
                                = temp1 80
                            )
                        )
                        (send gGameMusic2:setVol(temp1))
                    )
                )
            )
        )
    )


    (method (dispose)
        (super:dispose())
        DisposeScript(32)
        (if (== global119 22)
            (send gNarrator:modeless(0))
        )
        (if ((not proc0_2(69) and (== global120 2)) and (== global119 13))
            not proc0_3(69)
        )
        (if (== global119 14)
            0
        )(else
            (if (== gNewRoomNumber 650)
                (send gGameMusic1:fade(127 10 16 0))
                (send gGameMusic2:stop())
            )(else
                (if (== gNewRoomNumber 640)
                    (send gGameMusic2:fade(127 10 16 0))
                    (send gGameMusic1:stop())
                )(else
                    (send gGameMusic1:fade())
                    (send gGameMusic2:fade())
                )
            )
        )
    )


    (method (newRoom newRoomNumber)
        (if ((== newRoomNumber 230) and proc999_5(global119 8 9 20 22))
            = newRoomNumber 235
        )
        (if ((== newRoomNumber 310) and ((== global119 14) or (== global119 15)))
            proc0_15(1 16)
        )
        (super:newRoom(newRoomNumber))
    )

)
(instance sSepiaStart of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = global120 4
                = local0 1
                (send gIconBar:disable())
                PalVary(pvINIT 240 0)
                (send gGame:setCursor(996))
                = global119 20
                = gEgoMoveSpeed (send gEgo:moveSpeed)
                (send gEgo:
                    posn(330 150)
                    setSpeed(7)
                    wearingGuns(1)
                )
                = seconds 3
            )
            (case 1
                PalVary(pvREVERSE 5 0 1)
            )
            (case 2
                (send gGameMusic1:
                    number(653)
                    loop(-1)
                    flags(1)
                    play()
                )
                (send gFpMessager:say(18 0 0 0 self))
            )
            (case 3
                (send gGameMusic1:fade(0 3 1 0))
                (send gEgo:setMotion(MoveTo 140 150 self))
            )
            (case 4
                (send gGameMusic1:
                    number(652)
                    flags(1)
                    loop(-1)
                    play()
                    setVol(0)
                )
                (send gGameMusic2:
                    number(640)
                    flags(1)
                    loop(-1)
                    play()
                    setVol(0)
                )
                (send gEgo:
                    normalize()
                    setSpeed(gEgoMoveSpeed)
                    setMotion(0)
                    setHeading(180)
                )
                = local3 1
                (send gIconBar:enable())
                (send gGame:handsOn())
                (self:dispose())
            )
        )
    )

)
(instance sWaterBucket of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send client:setCel(0))
                = seconds Random(15 25)
            )
            (case 1
                (send client:show())
                (send client:
                    setCycle(End self)
                    cycleSpeed(5)
                )
                (slopSound:play())
            )
            (case 2
                (send client:hide())
                (self:changeState(0))
            )
        )
    )

)
(instance sRowdysKill of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gGame:handsOff())
                = seconds 4
            )
            (case 1
                (send gFpMessager:say(20 0 0 0 self))
            )
            (case 2
                (send gEgo:
                    view(142)
                    setLoop(0)
                    setCel(0)
                    setPri(1)
                    setSpeed(10)
                    setCycle(End self)
                )
            )
            (case 3
                = global122 6
                (send global2:newRoom(99))
                (self:dispose())
            )
        )
    )

)
(instance sBreezeShrubs of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = seconds Random(7 15)
            )
            (case 1
                (shrub1:
                    show()
                    setCycle(Fwd)
                )
                (shrub2:
                    show()
                    setCycle(Fwd)
                )
                = seconds Random(1 4)
            )
            (case 2
                (shrub1:hide())
                (shrub2:hide())
                UnLoad(128 242)
                (self:changeState(0))
            )
        )
    )

)
(instance bucket of Prop
    (properties
        x 92
        y 31
        z 20
        noun 19
        view 241
        priority 8
        signal $0010
    )
)
(instance storeDoor of Door
    (properties
        x 123
        y 93
        noun 16
        approachX 132
        approachY 100
        view 240
        entranceTo 650
        lockedCase 1
        openSnd 2146
        closeSnd 2147
        openVerb 4
        moveToX 132
        moveToY 91
        enterType 0
        exitType 0
    )
)
(instance storeDoorClosed of View
    (properties
        x 123
        y 93
        noun 17
        view 252
        loop 3
    )
)
(instance barberDoor of Door
    (properties
        x 305
        y 93
        noun 15
        approachX 313
        approachY 100
        view 240
        loop 1
        entranceTo 640
        lockedCase 1
        openSnd 2146
        closeSnd 2147
        openVerb 4
        moveToX 313
        moveToY 92
        enterType 0
        exitType 0
    )
)
(instance cowboy1 of Prop
    (properties
        x 190
        y 110
        view 101
    )

    (method (doit)
        (super:doit())
        (if (script)
        )(else
            (if ((local1 and (== view 101)) and (== cel 4))
                = local1 0
                (shot1:play(self))
            )
        )
    )


    (method (cue)
        = local1 1
    )

)
(instance cowboy2 of Prop
    (properties
        x 130
        y 158
        view 101
    )

    (method (doit)
        (super:doit())
        (if (script)
        )(else
            (if ((local2 and (== view 101)) and (== cel 4))
                = local2 0
                (shot2:play(self))
            )
        )
    )


    (method (cue)
        = local2 1
    )

)
(instance cowboy3 of Prop
    (properties
        x 68
        y 133
        view 101
    )
)
(instance cowboy4 of Prop
    (properties
        x 251
        y 157
        view 101
    )
)
(instance barberpole of Prop
    (properties
        x 266
        y 101
        noun 13
        view 240
        loop 2
    )
)
(instance shrub1 of Prop
    (properties
        y 189
        noun 21
        view 242
        priority 15
        signal $0010
    )
)
(instance shrub2 of Prop
    (properties
        x 118
        y 189
        noun 21
        view 242
        loop 1
        priority 15
        signal $0010
    )
)
(instance dummyCredits of Prop
    (properties
        x -10
        y -10
        view 996
    )
)
(instance store of Feature
    (properties
        x 158
        y 22
        noun 5
    )
)
(instance postOffice of Feature
    (properties
        x 238
        y 34
        noun 6
    )
)
(instance barberShop of Feature
    (properties
        x 292
        y 32
        noun 14
    )
)
(instance clutter of Feature
    (properties
        x 169
        y 167
        noun 9
    )
)
(instance storeWindow of Feature
    (properties
        x 177
        y 73
        noun 2
        nsTop 58
        nsLeft 153
        nsBottom 89
        nsRight 202
    )
)
(instance postWindow of Feature
    (properties
        x 254
        y 74
        noun 4
        nsTop 63
        nsLeft 246
        nsBottom 86
        nsRight 262
    )
)
(instance barberWindow of Feature
    (properties
        x 286
        y 79
        noun 3
        nsTop 67
        nsLeft 273
        nsBottom 91
        nsRight 300
    )
)
(instance storeSign of Feature
    (properties
        x 158
        y 22
        noun 11
        nsTop 7
        nsLeft 106
        nsBottom 37
        nsRight 210
    )
)
(instance postSign of Feature
    (properties
        x 238
        y 34
        noun 12
        nsTop 19
        nsLeft 213
        nsBottom 50
        nsRight 264
    )
)
(instance barberSign of Feature
    (properties
        x 292
        y 32
        noun 10
        nsTop 17
        nsLeft 265
        nsBottom 48
        nsRight 319
    )
)
(instance hotel of Feature
    (properties
        x 12
        y 60
        noun 7
        nsBottom 121
        nsRight 24
    )
)
(instance wagon of Feature
    (properties
        x 79
        y 73
        noun 8
        nsTop 56
        nsLeft 60
        nsBottom 91
        nsRight 98
    )
)
(instance postDoor of Feature
    (properties
        x 230
        y 81
        noun 22
        nsTop 63
        nsLeft 221
        nsBottom 100
        nsRight 240
        approachX 230
        approachY 104
    )
)
(instance slopSound of FPSound
    (properties
        flags $0001
        number 2241
    )
)
(instance shot1 of FPSound
    (properties
        flags $0001
        number 2944
    )
)
(instance shot2 of FPSound
    (properties
        flags $0001
        number 2944
    )
)
