-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTools.p
executable file
·391 lines (348 loc) · 9.21 KB
/
Tools.p
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
unit Tools;
interface
uses
Script, Sound, Globals, QDOffScreen,
Dialogs, ToolUtils, Resources, Menus, Processes, Fonts, gestaltEqu, Palettes, Events, LowMem;
procedure InitProg;
procedure InitSound;
procedure Quit;
procedure AppDebug (str: Str255);
procedure DoError (ID: integer);
procedure HideMenuBar;
procedure ShowMenuBar;
procedure ReHideMenuBar;
procedure EnterHighScore(points:longint);
procedure DisplayScores;
function RGB (R, G, B: integer): RGBColor;
function sign (Numb: integer): Integer;
procedure OffsetPt(var pt:point;h,v:integer);
implementation
procedure Quit;
function CheckGameend: boolean;
begin
CheckGameend := false;
if GamePlay then begin
if Alert(1003, nil) = 1 then
CheckGameend := true;
end else
CheckGameend := true;
end;
begin
if CheckGameEnd then
begin
ShowMenuBar;
if TheScreen^^.gdType = fixedType then
TheScreen^^.gdPMap^^.pmTable^^.ctseed := CTOrig;
if Olddepth<>TheScreen^^.gdPMap^^.pixelsize then
DoError(SetDepth(TheScreen,OldDepth,0,0));
ExitToShell;
end
end;
function sign (Numb: integer): Integer;
begin
if Numb <> 0 then
sign := Numb div abs(Numb)
else
sign := 1;
end;
function RGB (R, G, B: integer): RGBColor;
begin
RGB.Red := R;
RGB.Green := G;
RGB.Blue := B;
end;
procedure OffsetPt(var pt:point;h,v:integer);
begin
pt.h:=pt.h+h;
pt.v:=pt.v+v;
end;
procedure EffectCallBack (Chan: SndChannelPtr; cmd: SndCommand);
begin
end;
procedure InitSound;
begin
BitSet(@ErrFlags, 0);
if BitTst(@GamePrefs^^.GrafFlags,5) then
begin
if (EngineChannel = nil) and not SoundDisable then
DoError(SndNewChannel(EngineChannel, sampledSynth, initMono + initNoInterp, @EffectCallBack));
EngineChannel^.userInfo:=longint(GetResource('snd ',2000));
end;
if BitTst(@GamePrefs^^.GrafFlags,4) then
begin
if (EffectAChannel = nil) and not SoundDisable then
DoError(SndNewChannel(EffectAChannel, sampledSynth, initMono, @EffectCallBack));
if (EffectBChannel = nil) and not SoundDisable then
DoError(SndNewChannel(EffectBChannel, sampledSynth, initMono, @EffectCallBack));
end;
BitClr(@ErrFlags, 0);
end;
procedure Emergency;
begin
ExitToShell;
end;
procedure InitMac;
var i:integer;
begin
InitGraf(@qd.thePort);
InitFonts;
InitWindows;
InitMenus;
TEInit;
InitDialogs(@Emergency);
InitCursor;
MaxApplZone;
for i:=1 to 64 do
MoreMasters;
end;
procedure SystemCheck;
var
response:longint;
FastMac:boolean;
begin
if TheScreen^^.gdrect.right-TheScreen^^.gdrect.left < 620 then
begin
response:=Alert(1005,nil);
ExitToShell;
end;
DoError(Gestalt(gestaltSystemVersion,response));
if response < $0700 then
begin
response:=Alert(1006,nil);
if response = 1 then
ExitToShell;
end;
DoError(Gestalt(gestaltSoundAttr,response));
if BitTst(@response,gestaltStereoMixing) then
SoundDisable:=true;
FastMac:=false;
DoError(Gestalt(gestaltSystemVersion,response));
if response >= $0712 then
begin
DoError(Gestalt(gestaltSysArchitecture,response));
if (response >= gestaltPowerPC) then
FastMac:=true;
end;
DoError(Gestalt(gestaltProcessorType,response));
if (response>gestalt68030) then
FastMac:=true;
if not FastMac then
response:=Alert(1011,nil);
if TheScreen^^.gdPMap^^.pixelSize > 8 then
begin
if FastMac and (HasDepth(TheScreen,8,0,0)<>0) then
DoError(SetDepth(TheScreen,8,0,0))
else if (HasDepth(TheScreen,4,0,0)<>0) then
DoError(SetDepth(TheScreen,4,0,0))
end;
if TheScreen^^.gdPMap^^.pixelSize > 4 then
begin
if not FastMac and (HasDepth(TheScreen,4,0,0)<>0) then
DoError(SetDepth(TheScreen,4,0,0))
end;
if TheScreen^^.gdPMap^^.pixelSize < 4 then
begin
if not FastMac and (HasDepth(TheScreen,4,0,0)<>0) then
DoError(SetDepth(TheScreen,4,0,0))
else if HasDepth(TheScreen,8,0,0)<>0 then
DoError(SetDepth(TheScreen,8,0,0))
else begin
response:=Alert(1008,nil);
ExitToShell;
end;
end;
end;
procedure InitProg;
var
NullRect:Rect;
begin
InitMac;
TheScreen := GetGDevice;
OldDepth := GetGDevice^^.gdPMap^^.PixelSize;
SystemCheck;
CTorig := TheScreen^^.gdPMap^^.pmTable^^.ctseed;
Depth := GetGDevice^^.gdPMap^^.PixelSize;
GamePlay := False;
GamePrefs := PrefHandle(GetResource('SETT', 1000));
GameKeys := KeyHandle(GetResource('CTLS', 1000));
ShellWindow := GetNewWindow(1000, nil, Pointer(-1));
AppleMenu := GetMenu(1000);
AppendResMenu(AppleMenu, 'DRVR');
InsertMenu(AppleMenu, 0);
FileMenu := GetMenu(1001);
InsertMenu(FileMenu, 0);
OptMenu := GetMenu(1002);
InsertMenu(OptMenu, 0);
DrawMenuBar;
qd.randseed := TickCount;
InitSound;
Sf:=RGB($F000,$F000,$0);
Sb:=RGB(0,0,0);
TextFont(0);
SetRect(NullRect,0,0,1,1);
end;
procedure DoError (ID: integer);
var
ErrStr: Str255;
response:integer;
function Harmless: boolean;
begin
Harmless := false;
if (ID = notEnoughHardwareErr) or (ID = cantOpenHandler)then
begin
SetGDevice(TheScreen);
if BitTst(@ErrFlags, 0) then
begin
response := Alert(1002, nil);
if response = 1 then
ExitToShell
else
begin
SoundDisable:=TRUE;
Harmless := true;
end;
end;
end;
if (ID = memFullErr) or (ID = cNoMemErr) then
begin
SetGDevice(TheScreen);
response := Alert(1001, nil);
ExitToShell;
end;
if (ID=wPrErr) or (ID=flckdErr) then
begin
response:=Alert(1010,nil);
Harmless:=true;
end;
if (ID=resproblem) or (ID=badchannel) then Harmless:=true;
end;
begin
if ID<>noErr then
if not Harmless then
begin
SetGDevice(TheScreen);
NumToString(ID, ErrStr);
ParamText(ErrStr, '', '', '');
response := Alert(1000, nil);
ExitToShell;
end;
end;
procedure AppDebug (str: Str255);
var
x: integer;
GW: GworldPtr;
GD: GdHandle;
begin
getGWorld(GW, GD);
SetGWorld(CGrafPtr(RaceWindow), TheScreen);
ParamText(str, '', '', '');
x := alert(10000, nil);
SetGWorld(GW, GD);
end;
procedure HideMenuBar;
var
DrawRect:Rect;
begin
if RaceWindow<> nil then
begin
SetPort(RaceWindow);
SetOrigin(0,0);
RectRgn(RaceWindow^.visRgn,RaceWindow^.portRect);
SetRect(DrawRect,0,0,RaceWindow^.portRect.right,20);
FillRect(DrawRect,qd.black);
LMSetMBarHeight(0);
SetOrigin(-RaceWindow^.portrect.right div 2+310,-RaceWindow^.portrect.bottom div 2+240);
end;
end;
procedure ReHideMenuBar;
begin
if RaceWindow<> nil then
begin
SetPort(RaceWindow);
SetOrigin(0,0);
RectRgn(RaceWindow^.visRgn,RaceWindow^.portRect);
SetOrigin(-RaceWindow^.portrect.right div 2+310,-RaceWindow^.portrect.bottom div 2+240);
end;
end;
procedure ShowMenuBar;
var
VisRect:Rect;
begin
if RaceWindow<> nil then
begin
SetPort(RaceWindow);
SetOrigin(0,0);
SetRect(VisRect,0,20,RaceWindow^.portRect.right,RaceWindow^.portRect.bottom);
RectRgn(RaceWindow^.visRgn,VisRect);
SetOrigin(-RaceWindow^.portrect.right div 2+310,-RaceWindow^.portrect.bottom div 2+240);
end;
LMSetMBarHeight(20);
DrawMenuBar;
end;
procedure EnterHighScore(points:longint);
var
ScoreDlog: DialogPtr;
ItemData: Handle;
NameString: Str255;
hit,i:integer;
ignore:Rect;
procedure InsertScore(points:longint;Name:String;place:integer);
var
i:integer;
begin
for i:= 9 downto place do
begin
ScoreHandle(GetResource('HIGH',127+i+1))^^.Score:=ScoreHandle(GetResource('HIGH',127+i))^^.Score;
ScoreHandle(GetResource('HIGH',127+i+1))^^.Name:=ScoreHandle(GetResource('HIGH',127+i))^^.Name;
ChangedResource(GetResource('HIGH',127+i+1))
end;
ScoreHandle(GetResource('HIGH',127+place))^^.Score:=points;
ScoreHandle(GetResource('HIGH',127+place))^^.Name:=Name;
ChangedResource(GetResource('HIGH',127+place));
DisplayScores;
end;
begin
FlushEvents(everyEvent,0);
if not Cheater then
if points > ScoreHandle(GetResource('HIGH',138))^^.Score then
begin
ScoreDlog := GetNewDialog(2006, nil, Pointer(-1));
DoError(SetDialogDefaultItem(ScoreDlog, 1));
SelectDialogItemText(ScoreDlog, 2, 0, maxint);
repeat
ModalDialog(nil, hit);
until hit=1;
GetDialogItem(ScoreDlog, 2, i, ItemData, ignore);
GetDialogItemText(ItemData, NameString);
DisposeDialog(ScoreDlog);
for i:= 10 downto 1 do
if points < ScoreHandle(GetResource('HIGH',127+i))^^.Score then begin
InsertScore(points,NameString,i+1);
Exit(EnterHighScore);
end else if i= 1 then
InsertScore(points,NameString,1)
end;
end;
procedure DisplayScores;
var
ScoreList:DialogPtr;
ItemData:Handle;
ScoreString:Str255;
Hit,i:integer;
ignore:Rect;
begin
ScoreList:=GetNewDialog(2004,nil,Pointer(-1));
for i := 1 to 10 do
begin
GetDialogItem(ScoreList, i+1, Hit, ItemData, ignore);
SetDialogItemText(ItemData, ScoreHandle(GetResource('HIGH',127+i))^^.Name);
NumToString(ScoreHandle(GetResource('HIGH',127+i))^^.Score,ScoreString);
GetDialogItem(ScoreList, i+11, Hit, ItemData, ignore);
SetDialogItemText(ItemData, Scorestring);
end;
Hit:=0;
while Hit<>1 do
ModalDialog(nil,Hit);
DisposeDialog(ScoreList);
end;
END.