(version 2)
(include "sci.sh")
(exports
    0 rm640
)
(use "Main")
(use "FPRoom")
(use "Scaler")
(use "ROsc")
(use "Polygon")
(use "CueObj")
(use "Cycle")
(use "View")
(use "Obj")
(script 640)


(local
    local0
    local1
    local2

)
(instance public rm640 of FPRoom
    (properties
        noun 15
        picture 640
        style $0064
        east 240
    )

    (method (init)
        (send gEgo:
            init()
            setScale(Scaler 156 101 170 130)
            normalize()
        )
        (altego:
            view(800)
            x(103)
            y(100)
            setPri(1)
            setScale(-1 gEgo)
            init()
        )
        (switch (gGNumber)
            (case east
                (send global2:setScript(sEnterFrom240))
            )
            (case 320
                (send global2:setScript(sEnterFrom320))
            )
            (case 680
                (send gGame:handsOn())
            )
            (default 
                (send gEgo:
                    x(160)
                    y(160)
                )
                (send gGame:handsOn())
            )
        )
        (super:init())
        (send global2:addObstacle((send ((Polygon:new())):
                type(2)
                init(319 189 0 189 0 0 319 0 319 138 200 138 200 149 107 149 70 170 319 170)
                yourself()
            )
 (send ((Polygon:new())):
                type(2)
                init(319 155 243 155 243 141 319 141)
                yourself()
            )
))
        (if (== gGNumber 320)
            (backDoor:
                approachVerbs(4)
                cel(5)
                init()
            )
        )(else
            (backDoor:
                approachVerbs(4)
                init()
            )
        )
        (if (proc0_2(35))
            (postcards:
                ignoreActors()
                addToPic()
                init()
            )
        )
        (if (not (send gEgo:has(2)) and (<= global119 19))
            (boots:init())
        )
        (if ((not (send gEgo:has(39)) and not proc0_2(33)) and (< global119 23))
            (gas:init())
        )
        (if (<= global120 2)
            (barber:
                loop(1)
                cel(0)
                priority(6)
                approachVerbs(4 2 9)
                setScript(sCutHair)
                init()
            )
            (manInChair:
                ignoreActors()
                addToPic()
                init()
            )
        )(else
            (if (== global120 3)
                (barber:
                    view(644)
                    loop(0)
                    cel(0)
                    x(140)
                    y(140)
                    approachVerbs(4 2 9)
                    setCycle(Fwd)
                    setScript(sSingSong)
                    init()
                )
                (manWaiting:
                    init()
                    setScript(sManReads)
                )
            )(else
                (if (== global120 4)
                    (barber:
                        view(642)
                        loop(1)
                        cel(0)
                        x(170)
                        y(139)
                        cycleSpeed(12)
                        approachVerbs(4 2 9)
                        setScript(sPullTeeth)
                        init()
                    )
                )
            )
        )
        (bowl:
            init()
            setOnMeCheck(1 4)
        )
        (bottle1:
            init()
            setOnMeCheck(1 8)
        )
        (bottle2:
            init()
            setOnMeCheck(1 16)
        )
        (bottles3:
            init()
            setOnMeCheck(1 32)
        )
        (stove:
            init()
            setOnMeCheck(1 64)
        )
        (bench:
            init()
            setOnMeCheck(1 128)
        )
        (buffalo:
            init()
            setOnMeCheck(1 256)
        )
        (lamp:
            init()
            setOnMeCheck(1 512)
        )
        (pitcher:
            init()
            setOnMeCheck(1 1024)
        )
        (chair:
            init()
            setOnMeCheck(1 2048)
        )
        (counter:
            init()
            setOnMeCheck(1 4096)
        )
        (shelf:
            init()
            setOnMeCheck(1 8192)
        )
        (topShelf:
            init()
            setOnMeCheck(1 16384)
        )
        (bottomShelf1:
            init()
            setOnMeCheck(26505)
        )
        (bottomShelf2:
            init()
            setOnMeCheck(26505)
        )
        (frame1:
            init()
            setOnMeCheck(26505)
        )
        (frame2:
            init()
            setOnMeCheck(26505)
        )
        (frame3:
            init()
            setOnMeCheck(26505)
        )
        (cabinet:
            init()
            setOnMeCheck(26505)
        )
        (if (== gGNumber 240)
            0
        )(else
            (send gGameMusic2:
                number(640)
                flags(1)
                loop(-1)
                play()
            )
        )
    )


    (method (doit)
        (super:doit())
        (if (script)
        )(else
            (if (proc0_1(gEgo 2))
                (send global2:setScript(sExitTo320))
            )
        )
    )


    (method (dispose)
        (super:dispose())
        (send gGameMusic2:fade(80 10 16 0))
    )

)
(instance sEnterFrom320 of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (backDoor:setCycle(Beg self))
                (send gEgo:
                    x(360)
                    y(138)
                    setHeading(0)
                )
            )
            (case 1
                (send gEgo:setMotion(MoveTo 250 138 self))
                (backDoor:stopUpd())
            )
            (case 2
                (send gGame:handsOn())
                (self:dispose())
            )
        )
    )

)
(instance sExitTo320 of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gGame:handsOff())
                (send gEgo:setMotion(MoveTo 360 139 self))
            )
            (case 1
                (send gEgo:setHeading(0))
                = cycles 3
            )
            (case 2
                (backDoor:setCycle(End self))
            )
            (case 3
                (send global2:newRoom(320))
                (self:dispose())
            )
        )
    )

)
(instance sEnterFrom240 of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gEgo:
                    x(330)
                    y(170)
                    setMotion(MoveTo 270 170 self)
                )
            )
            (case 1
                (send gGame:handsOn())
                (self:dispose())
            )
        )
    )

)
(instance sCutHair of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (barber:
                    loop(1)
                    cel(0)
                    setCycle(CT 3 1 self)
                )
            )
            (case 1
                (cuttingSound:
                    number(2643)
                    play(self)
                )
            )
            (case 2
                (barber:setCycle(CT 5 1 self))
            )
            (case 3
                (cuttingSound:
                    number(2643)
                    play(self)
                )
            )
            (case 4
                (if (== local0 5)
                    = local0 0
                    = cycles 1
                )(else
                    ++local0
                    (self:changeState(0))
                )
            )
            (case 5
                (barber:
                    loop(0)
                    cel(0)
                    setCycle(ROsc 1 0 4 self)
                )
            )
            (case 6
                (cuttingSound:
                    number(2642)
                    play()
                )
                (barber:cel(5))
                = ticks 40
            )
            (case 7
                (if (== local0 3)
                    = local0 0
                    (self:changeState(0))
                )(else
                    ++local0
                    (self:changeState(5))
                )
            )
        )
    )

)
(instance sPullTeeth of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if (== Random(4 7) 5)
                    (barber:
                        view(642)
                        loop(1)
                        cel(0)
                        setCycle(Fwd)
                    )
                    = seconds Random(5 10)
                )(else
                    = seconds Random(1 3)
                )
            )
            (case 1
                (if (== Random(4 9) 7)
                    (cuttingSound:
                        number(2641)
                        play()
                    )
                    (barber:
                        loop(0)
                        cel(0)
                        setCycle(End self)
                    )
                )(else
                    (self:changeState(0))
                )
            )
            (case 2
                (barber:
                    view(648)
                    loop(0)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 3
                = seconds 2
            )
            (case 4
                (barber:
                    view(647)
                    loop(0)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 5
                UnLoad(128 647)
                UnLoad(128 648)
                (self:changeState(0))
            )
        )
    )

)
(instance sSingSong of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = cycles 1
            )
            (case 1
                (switch (Random(0 3))
                    (case 0
                        (barber:setCycle(CT Random(0 9) 1 self))
                    )
                    (case 1
                        (barber:setCycle(CT Random(0 9) -1 self))
                    )
                    (case 2
                        (barber:setCycle(CT Random(0 9) 1 self))
                    )
                    (case 3
                        (barber:setCycle(CT Random(0 9) -1 self))
                    )
                )
            )
            (case 2
                (self:changeState(1))
            )
        )
    )

)
(instance sManReads of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (manWaiting:
                    setCel(0)
                    setCycle(End self)
                )
            )
            (case 1
                (manWaiting:stopUpd())
                = seconds Random(5 10)
            )
            (case 2
                (self:changeState(0))
            )
        )
    )

)
(instance altego of Actor
    (properties
        x 103
        y 100
        noun 21
        view 800
        priority 1
        signal $5000
    )

    (method (init)
        (super:init())
        (self:view((send gEgo:view)))
    )


    (method (doit)
        (var temp0)
        = temp0 (- (send gEgo:y) 125)
        (self:
            loop(
                (switch ((send gEgo:loop))
                    (case 0
                        1
                    )
                    (case 1
                        0
                    )
                    (case 2
                        5
                    )
                    (case 3
                        6
                    )
                    (case 4
                        5
                    )
                    (case 5
                        5
                    )
                    (case 6
                        6
                    )
                    (case 7
                        6
                    )
                    (case 8
                        8
                    )
                )
)
            cel(
                (switch ((send gEgo:cel))
                    (case 0
                        1
                    )
                    (case 1
                        0
                    )
                    (case 2
                        2
                    )
                    (case 3
                        3
                    )
                    (case 4
                        5
                    )
                    (case 5
                        5
                    )
                    (case 6
                        6
                    )
                    (case 7
                        6
                    )
                )
)
            x(+ (- 10 temp0) (- (- 100 (* 2 temp0)) (/ (- (send gEgo:x) 130) 5)))
            y((send gEgo:y))
            setPri(- (send gEgo:priority) 8)
        )
        (super:doit())
    )

)
(instance barber of Actor
    (properties
        x 146
        y 133
        noun 2
        approachX 178
        approachY 149
        view 643
        loop 1
        signal $5000
        cycleSpeed 12
        moveSpeed 12
    )

    (method (doVerb theVerb param2)
        (switch (theVerb)
            (case 2
                (if (<= global120 1)
                    (switch (global136)
                        (case 0
                            (send gFpMessager:say(noun theVerb 1))
                            ++global136
                        )
                        (case 1
                            (send gFpMessager:say(noun theVerb 2))
                            ++global136
                        )
                        (case 2
                            (send gFpMessager:say(noun theVerb 3))
                        )
                    )
                )(else
                    (if ((== global119 8) or (== global119 9))
                        (send gFpMessager:say(noun theVerb 4))
                    )(else
                        (if (== global119 10)
                            (send gFpMessager:say(noun theVerb 5))
                        )(else
                            (if (== global119 12)
                                (send gFpMessager:say(noun theVerb 6))
                            )(else
                                (if (== global119 13)
                                    (send gFpMessager:say(noun theVerb 7))
                                )(else
                                    (if ((== global119 16) or (== global119 17))
                                        (send gFpMessager:say(noun theVerb 9))
                                    )(else
                                        (if (== global119 19)
                                            (send gFpMessager:say(noun theVerb 8))
                                        )(else
                                            (if (== global119 20)
                                                (send gFpMessager:say(noun theVerb 10))
                                            )(else
                                                (if (== global119 22)
                                                    (send gFpMessager:say(noun theVerb 11))
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
            (case 1
                (if (== global120 3)
                    (send gFpMessager:say(noun theVerb 12))
                )(else
                    (super:doVerb(theVerb rest param2))
                )
            )
            (case 4
                (if (== global120 3)
                    (send gFpMessager:say(noun theVerb 12))
                )(else
                    (super:doVerb(theVerb rest param2))
                )
            )
            (case 57
                (send gEgo:put(7))
                (send gEgo:get(-1 2))
                (if ((((send gEgo:has(38)) and (send gEgo:has(10))) and (send gEgo:has(52))) and (send gEgo:has(44)))
                    proc0_3(58)
                )
                = local1 1
                (send gGame:points(5))
                (send gFpMessager:say(2 57 0 0 self))
            )
            (case 42
                (send gEgo:put(45))
                (send gEgo:get(-1 39))
                proc0_3(35)
                = local2 1
                (send gGame:points(5))
                (send gFpMessager:say(2 42 0 0 self))
            )
            (default 
                (super:doVerb(theVerb rest param2))
            )
        )
    )


    (method (cue)
        (super:cue())
        (if (local1)
            (boots:dispose())
            = local1 0
        )(else
            (if (local2)
                (gas:dispose())
                = local2 0
            )
        )
    )

)
(instance backDoor of Prop
    (properties
        y 106
        noun 16
        approachX 310
        approachY 139
        view 640
        priority 1
        signal $4011
    )
)
(instance manWaiting of Prop
    (properties
        x 253
        y 133
        noun 26
        view 641
        signal $4000
    )
)
(instance boots of View
    (properties
        x 208
        y 118
        noun 22
        view 640
        loop 3
        signal $4000
    )
)
(instance postcards of View
    (properties
        x 233
        y 124
        z 13
        noun 23
        view 640
        loop 2
        signal $4000
    )
)
(instance gas of View
    (properties
        x 197
        y 84
        noun 24
        view 640
        loop 1
        signal $4000
    )
)
(instance manInChair of View
    (properties
        x 137
        y 114
        noun 2
        view 649
        priority 10
        signal $4010
    )
)
(instance bowl of Feature
    (properties
        x 162
        y 189
        noun 3
    )
)
(instance bottle1 of Feature
    (properties
        x 107
        y 189
        noun 4
    )
)
(instance bottle2 of Feature
    (properties
        x 70
        y 189
        noun 5
    )
)
(instance bottles3 of Feature
    (properties
        x 21
        y 189
        noun 6
    )
)
(instance stove of Feature
    (properties
        x 289
        y 146
        noun 7
    )
)
(instance bench of Feature
    (properties
        x 257
        y 123
        noun 8
    )
)
(instance buffalo of Feature
    (properties
        x 245
        y 123
        noun 9
    )
)
(instance lamp of Feature
    (properties
        x 199
        y 123
        noun 10
    )
)
(instance pitcher of Feature
    (properties
        x 70
        y 149
        noun 11
    )
)
(instance chair of Feature
    (properties
        x 134
        y 110
        noun 12
    )
)
(instance counter of Feature
    (properties
        x 88
        y 185
        noun 13
    )
)
(instance shelf of Feature
    (properties
        x 148
        y 123
        noun 14
    )
)
(instance topShelf of Feature
    (properties
        x 148
        y 80
        noun 19
    )
)
(instance bottomShelf1 of Feature
    (properties
        x 153
        y 83
        noun 20
        nsTop 76
        nsLeft 135
        nsBottom 91
        nsRight 171
    )
)
(instance bottomShelf2 of Feature
    (properties
        x 110
        y 83
        noun 20
        nsTop 76
        nsLeft 93
        nsBottom 91
        nsRight 127
    )
)
(instance frame1 of Feature
    (properties
        x 159
        y 188
        noun 15
        nsLeft 41
        nsBottom 188
        nsRight 59
    )
)
(instance frame2 of Feature
    (properties
        x 157
        y 187
        noun 15
        nsTop 167
        nsBottom 184
        nsRight 319
    )
)
(instance frame3 of Feature
    (properties
        x 157
        y 189
        noun 15
        nsLeft 307
        nsBottom 189
        nsRight 319
    )
)
(instance cabinet of Feature
    (properties
        x 191
        y 83
        noun 18
        nsTop 89
        nsLeft 177
        nsBottom 128
        nsRight 205
    )
)
(instance cuttingSound of FPSound
    (properties
        flags $0001
    )
)
