(version 2)
(include "sci.sh")
(exports
    0 TheGame
    1 proc0_1
    2 proc0_2
    3 proc0_3
    4 runScript
)
(use "Print")
(use "Messager")
(use "Blink")
(use "PseudoMouse")
(use "n958")
(use "Grooper")
(use "SysWindow")
(use "Ego")
(use "Sound")
(use "Game")
(use "User")
(use "View")
(use "Obj")
(script 0)

(local
    gEgoObj
    global1
    global2
    global3
    global4
    global5
    global6
    global7
    global8
    global9
    global10
    global11
    global12
    global13
    global14
    global15
    global16
    global17
    global18
    gCursorObj
    global20 =     999
    global21 =     997
    global22 =     1
    global23 =     4
    global24
    global25
    global26 =     1
    global27
    global28
    global29
    global30
    global31
    global32
    global33
    global34
    global35
    global36 =     -1
    global37
    gSysWindow
    global39
    global40
    global41
    global42
    global43
    global44
    global45
    global46
    global47
    global48
    global49
    global50
    global51
    global52
    global53
    global54
    global55
    global56
    global57
    global58
    global59
    global60
    global61
    global62
    global63
    global64
    global65
    global66
    global67 =     1
    global68
    global69
    global70
    global71
    gKH
    gMH
    gDH
    global75
    global76
    gPseudoMouse
    global78
    global79 =     60
    global80
    global81
    global82
    global83
    global84
    global85
    global86
    global87
    global88
    gNarrator
    global90 =     1
    gGameMessager
    global92
    global93
    global94 =     2
    global95
    global96
    global97
    global98
    global99
    global100
    global101 =     1234
    gDemoSound
    global103 =     1
    global104 =     1
    global105 =     1
    global106 =     1
    global107
    global108
    global109
    global110
    global111 =     7
    gPSound
    global113
    global114
    gStopGroop
    global116
    global117 =     1
    global118 =     12
    global119
    global120
    global121
    global122
    global123 =     -1
    global124 =     175
    global125 =     280
    global126 =     360
    global127 =     470
    global128 =     590
    global129 =     685
    global130 =     785
    global131 =     865
    global132 =     975
    global133 =     1080
    global134 =     1165
    global135 =     1275
    global136
    global137
    global138
    global139
    global140
    gLongSong
    gLongSong2
    global143
    gLongSong3
    global145
    global146
    global147
    global148
    global149
    global150
    global151
    global152
    global153
    global154
    global155
    global156
    global157
    global158
    global159
    global160
    global161
    global162
    global163
    global164
    global165
    global166
    global167
    global168
    global169
    global170
    global171
    global172
    global173
    global174
    global175
    global176
    global177
    global178
    global179
    global180
    global181
    global182
    global183
    global184
    global185
    global186
    global187
    global188
    global189
    global190
    global191
    global192
    global193
    global194
    global195
    global196
    global197
    global198
    global199
    global200
    global201
    global202
    global203
    global204
    global205
    global206
    global207
    global208
    global209
    global210
    global211
    global212
    global213
    global214
    global215
    global216
    global217
    global218
    global219
    global220
    global221
    global222
    global223
    global224
    global225
    global226
    global227
    global228
    global229
    global230
    global231
    global232
    global233
    global234
    global235
    global236
    global237
    global238
    global239
    global240
    global241
    global242
    global243
    global244
    global245
    global246
    global247
    global248
    global249
    global250
    global251
    global252
    global253
    global254
    global255
    global256
    global257
    global258
    global259
    global260
    global261
    global262
    global263
    global264
    global265
    global266
    global267
    global268
    global269
    global270
    global271
    global272
    global273
    global274
    global275
    global276
    global277
    global278
    global279
    global280
    global281
    global282
    global283
    global284
    global285
    global286
    global287
    global288
    global289
    global290
    global291
    global292
    global293
    global294
    global295
    global296
    global297
    global298
    global299
    global300

)
(procedure public (proc0_1 param1)
    = global250[(/ param1 16)] (| global250[(/ param1 16)] (>> $8000 (% param1 16)))
)


(procedure public (proc0_2 param1)
    = global250[(/ param1 16)] (& global250[(/ param1 16)] bnot (>> $8000 (% param1 16)))
)


(procedure public (proc0_3 param1)
    return & global250[(/ param1 16)] (>> $8000 (% param1 16))
)

(instance demoSound of Sound
    (properties)
)
(instance pSound of Sound
    (properties
        flags $0001
        number 907
    )
)
(instance egoObj of Ego
    (properties)
)
(instance public TheGame of Game
    (properties)

    (method (init)
        (var temp0, temp1, temp2[100], temp102, temp103[20])
        proc958_0(130 982)
        (super:init())
        StrCpy(@global42 "")
        = global27 "x.yyy.zzz"
        = global107 "mm/dd/yy"
        = global108 "991-999-9999"
        = global109 "992-999-9999"
        = temp1 FileIO(fiOPEN "version" 1)
        FileIO(fiREAD_STRING global27 11 temp1)
        FileIO(fiREAD_STRING global108 20 temp1)
        FileIO(fiREAD_STRING global109 20 temp1)
        FileIO(fiREAD_STRING global108 20 temp1)
        FileIO(fiCLOSE temp1)
        = gSysWindow SysWindow
        = global22 4
        (Print:font(global22))
        = gNarrator Narrator
        (send gNarrator:
            font(global22)
            back(11)
            keepWindow(1)
        )
        = global90 1
        = global34 1
        = global79 30
        = global94 2
        = gPseudoMouse PseudoMouse
        = global113 DoSound(sndGET_POLYPHONY)
        = global114 Graph(grGET_COLOURS)
        (if ((>= global114 2) and (<= global114 16))
            proc0_2(1)
        )(else
            proc0_1(1)
        )
        (send gSysWindow:
            color(global110)
            back(global111)
        )
        = gStopGroop stopGroop
        (self:setCursor(999 1 160 160))
        = gEgoObj egoObj
        (User:
            alterEgo(gEgoObj)
            canControl(0)
            canInput(0)
        )
        = gDemoSound demoSound
        = gGameMessager gameMessager
        = gMH MH
        (send gMH:add())
        = gKH KH
        (send gKH:add())
        = gDH DH
        (send gDH:add())
        = gPSound pSound
        (send gPSound:
            owner(self)
            init()
        )
        = gLongSong longSong
        (send gLongSong:
            owner(self)
            priority(15)
            init()
        )
        = gLongSong2 longSong2
        (send gLongSong2:
            owner(self)
            priority(15)
            init()
        )
        = gLongSong3 longSong3
        (send gLongSong3:
            owner(self)
            priority(15)
            init()
        )
        (send gKH:addToFront(TheGame))
        (if (FileIO(fiEXISTS "880.scr"))
            (while (1)
                = temp103 0
                = temp102 (Print:
                        font(global23)
                        addText("Enter room number..." 0 0)
                        addEdit(@temp103 5 125 0)
                        init()
                    )
                (if (temp103)
                    = temp102 ReadNumber(@temp103)
                )
                (if (> temp102 0)
                    break
                )
            )
            (send global1:masterVolume(15))
            (if (<> Platform(4 0) 1)
                = global143 1
            )
            (if (< temp102 13)
                = global106 temp102
            )
            (self:newRoom(temp102))
        )(else
            (self:newRoom(812))
        )
    )


    (method (startRoom param1)
        (if (gPseudoMouse)
            (send gPseudoMouse:stop())
        )
        (rightArrow:
            dispose()
            delete()
        )
        (leftArrow:
            dispose()
            delete()
        )
        (stopButton:
            dispose()
            delete()
        )
        proc958_0(0 813 814 815 816 922 982 255 929 941 961 806 805 807 808 809 874 830 991 948)
        (send gKH:delete(TheGame))
        (if (>u MemoryInfo(1) (+ 10 MemoryInfo(0)))
            (if (global25)
                (send global25:dispose())
            )
            proc921_0("Memory fragmented.")
            SetDebug()
        )
        (send gKH:addToFront(TheGame))
        (if (not proc999_5(global11 812 804 111 801 802 803))
            = global119 global123[global11]
        )(else
            = global119 9
        )
        (if (<> global11 13)
            (stopButton:
                view(global119)
                init()
                stopUpd()
            )
            (leftArrow:
                view(global119)
                init()
                stopUpd()
            )
            (rightArrow:
                view(global119)
                init()
                stopUpd()
            )
        )
        (super:startRoom(param1))
    )


    (method (handleEvent pEvent param2)
        (if ((send pEvent:claimed))
            return 1
        )
        (if ((((== (send pEvent:type) evKEYBOARD) or (== (send pEvent:type) evMOUSEBUTTON)) and not (== global11 801)) and (== global120 1))
            = global120 0
            (super:handleEvent(pEvent))
        )
        return 
            (if (((== (send gCursorObj:cel) 10) and (== (send pEvent:type) evKEYBOARD)) and (== (User:canInput()) 1))
                (switch ((send pEvent:message))
                    (case KEY_SPACE
                        (if (<> global11 111)
                            (send pEvent:claimed(1))
                            (stopButton:setScript(stopButtonScript))
                        )
                    )
                    (case KEY_f
                        (if (not proc999_5(global11 801 802 803 812 817))
                            (send pEvent:claimed(1))
                            (rightArrow:setScript(rightArrowScript))
                        )
                    )
                    (case KEY_b
                        (if (not proc999_5(global11 801 803 812 817))
                            (send pEvent:claimed(1))
                            (leftArrow:setScript(leftArrowScript))
                        )
                    )
                    (case KEY_p
                        = global120 0
                        (send pEvent:claimed(1))
                    )
                    (case KEY_r
                        = global120 1
                        (send pEvent:claimed(1))
                        (rightArrow:setScript(rightArrowScript))
                    )
                    (case KEY_RETURN
                        (if ((< (send pEvent:x) 15) and (> (send pEvent:y) 185))
                            (send pEvent:claimed(1))
                            (leftArrow:setScript(leftArrowScript))
                        )(else
                            (if ((> (send pEvent:x) 308) and (> (send pEvent:y) 185))
                                (send pEvent:claimed(1))
                                (rightArrow:setScript(rightArrowScript))
                            )(else
                                (if (== OnControl(4 (send pEvent:x) (send pEvent:y)) 8)
                                    (send pEvent:claimed(1))
                                    (stopButton:setScript(stopButtonScript))
                                )
                            )
                        )
                    )
                    (default 
                        (if (FileIO(fiEXISTS "880.SCR"))
                            (send pEvent:claimed(0))
                            (send (ScriptID(880)):handleEvent(pEvent))
                            (send (ScriptID(880)):dispose())
                            DisposeScript(880)
                        )
                    )
                )
            )(else
                (if (((== (send gCursorObj:cel) 10) and ((== (send pEvent:type) evKEYBOARD) or (== (send pEvent:type) evMOUSEBUTTON))) and (== (User:canInput()) 1))
                    (if ((< (send pEvent:x) 20) and (> (send pEvent:y) 175))
                        (send pEvent:claimed(1))
                        (leftArrow:setScript(leftArrowScript))
                    )(else
                        (if ((> (send pEvent:x) 300) and (> (send pEvent:y) 175))
                            (send pEvent:claimed(1))
                            (rightArrow:setScript(rightArrowScript))
                        )(else
                            (if (== OnControl(4 (send pEvent:x) (send pEvent:y)) 8)
                                (send pEvent:claimed(1))
                                (stopButton:setScript(stopButtonScript))
                            )
                        )
                    )
                )(else
                    (if (FileIO(fiEXISTS "880.SCR"))
                        (send pEvent:claimed(0))
                        (send (ScriptID(880)):handleEvent(pEvent))
                        (send (ScriptID(880)):dispose())
                        DisposeScript(880)
                    )(else
                        (super:handleEvent(pEvent rest param2))
                    )
                )
            )
    )


    (method (setCursor cursorNumber param2 param3 param4)
        (var temp0)
        (if (IsObject(cursorNumber))
            (send gCursorObj:init())
        )(else
            = gCursorObj cursorObj
            (send gCursorObj:
                view(990)
                loop(0)
                setCel(
                    (switch (cursorNumber)
                        (case 999
                            10
                        )
                        (case 998
                            11
                        )
                        (case 997
                            12
                        )
                        (case 996
                            0
                        )
                        (default 
                            cursorNumber
                        )
                    )
)
                init()
            )
        )
        (if ((> paramTotal 1) and not param2)
            = gCursorObj cursorObj
            (send gCursorObj:
                view(996)
                loop(0)
                setCel(0)
                init()
            )
        )
        (if (> paramTotal 2)
            (send gCursorObj:posn(param3 param4))
        )
    )


    (method (handsOff)
        (super:handsOff())
        (send global80:
            canInput(0)
            canControl(0)
        )
        (if (not HaveMouse())
            (send global1:setCursor(996))
        )(else
            (send global1:setCursor(global21))
        )
    )


    (method (handsOn)
        (super:handsOn())
        (self:setCursor(999 1))
        (send global80:canInput(1))
        (send global80:canControl(0))
    )

)
(instance stopGroop of Grooper
    (properties)
)
(instance MH of EventHandler
    (properties)
)
(instance KH of EventHandler
    (properties)
)
(instance DH of EventHandler
    (properties)
)
(instance gameMessager of Messager
    (properties)

    (method (findTalker param1)
        (var temp0)
        = temp0 
            (switch (param1)
                (case 99
                    gNarrator
                )
                (default 
                    gNarrator
                )
            )
        (if (temp0)
            return 
        )(else
            (super:findTalker(param1))
        )
    )

)
(instance cursorObj of Cursor
    (properties)
)
(instance leftArrow of Prop
    (properties
        x 11
        y 196
        priority 15
        signal $0010
    )
)
(instance rightArrow of Prop
    (properties
        x 308
        y 196
        loop 1
        priority 15
        signal $0010
    )
)
(instance stopButton of Prop
    (properties
        x 158
        y 158
        loop 2
        priority 15
        signal $0010
    )
)
(instance leftArrowScript of Script
    (properties)

    (method (changeState newState)
        (var temp0[10], temp10)
        (switch (= state newState)
            (case 0
                (if (proc999_5(global11 13 111 801 803 812 817))
                    (self:dispose())
                )(else
                    (send global1:handsOff())
                    = temp10 global106
                    (leftArrow:
                        view(global119)
                        setCel(1)
                    )
                    = cycles 2
                )
            )
            (case 1
                (mySound:
                    number(910)
                    loop(1)
                    play()
                )
                = ticks 24
            )
            (case 2
                (leftArrow:setCel(0))
                = ticks 6
            )
            (case 3
                (if (== global106 1)
                    (self:cue())
                )(else
                    --global106
                )
                (if (not == global11 801)
                    (switch (global11)
                        (case 1
                            (send global2:newRoom(801))
                        )
                        (default 
                            (send global2:newRoom(global106))
                        )
                    )
                )(else
                    (send global2:newRoom(801))
                )
            )
        )
    )

)
(instance rightArrowScript of Script
    (properties)

    (method (changeState newState)
        (var temp0[10], temp10)
        (switch (= state newState)
            (case 0
                (if (proc999_5(global11 812 804 111 801 802 803 817))
                    (self:dispose())
                )(else
                    (send global1:handsOff())
                    = temp10 global106
                    (rightArrow:
                        view(global119)
                        setCel(1)
                    )
                    = cycles 2
                )
            )
            (case 1
                (mySound:
                    number(910)
                    loop(1)
                    play()
                )
                = ticks 24
            )
            (case 2
                (rightArrow:setCel(0))
                = ticks 6
            )
            (case 3
                (if (== global106 global118)
                    == global106 global118
                )(else
                    ++global106
                )
                (if (not == global11 801)
                    (switch (global11)
                        (case 12
                            (send global2:newRoom(804))
                        )
                        (default 
                            (send global2:newRoom(global106))
                        )
                    )
                )(else
                    (send global2:newRoom(801))
                )
            )
        )
    )

)
(instance stopButtonScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send global1:handsOff())
                (stopButton:
                    view(global119)
                    setCel(1)
                )
                = cycles 2
            )
            (case 1
                (mySound:
                    number(910)
                    loop(1)
                    play()
                )
                = ticks 24
            )
            (case 2
                (stopButton:setCel(0))
                = ticks 6
            )
            (case 3
                (if (not == global11 801)
                    (send global2:newRoom(801))
                )(else
                    (send global2:newRoom(803))
                )
            )
        )
    )

)
(instance public runScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send global1:handsOn())
                (if (global120)
                    = ticks 250
                )(else
                    (self:dispose())
                )
            )
            (case 1
                (if (global120)
                    (mySound:
                        number(910)
                        loop(1)
                        play()
                    )
                    (rightArrow:
                        view(global119)
                        setCel(1)
                        init()
                    )
                    = ticks 24
                )
            )
            (case 2
                (rightArrow:setCel(0))
                = ticks 6
            )
            (case 3
                (if (== global106 global118)
                    (send global2:newRoom(801))
                )(else
                    ++global106
                )
                (send global1:handsOff())
                (send global2:newRoom(global106))
                (self:dispose())
            )
        )
    )

)
(instance longSong of Sound
    (properties
        flags $0001
        loop -1
    )
)
(instance longSong2 of Sound
    (properties
        flags $0001
        loop -1
    )
)
(instance longSong3 of Sound
    (properties
        flags $0001
        loop -1
    )
)
(instance mySound of Sound
    (properties)
)
