forked from ericlangedijk/Lemmix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStyles.Dos.pas
640 lines (561 loc) · 19.3 KB
/
Styles.Dos.pas
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
unit Styles.Dos;
{$include lem_directives.inc}
interface
uses
Classes, SysUtils,
Base.Utils,
Prog.Base, Prog.Data,
Dos.Consts,
Styles.Base;
// this unit contains the classes for the 6 original dos styles
type
TDosOrigStyle = class sealed(TStyle)
protected
function GetLevelSystemClass: TLevelSystemClass; override;
function GetMechanics: TMechanics; override;
// todo: add GetMainDatFileName virtual
end;
TDosOrigLevelSystem = class(TLevelSystem)
strict private
type
TDosOrigLevelOrderTable = array[1..4, 1..30] of Byte; // fun..mayhem, 1..30 encoded indices (note: the levels are 1-based)
const
SectionTable: TDosOrigLevelOrderTable = (
(
147, 155, 157, 149, 151, 153, 159, 14, 22, 54,
70, 16, 29, 32, 38, 42, 48, 72, 84, 104,
138, 23, 68, 96, 98, 116, 78, 100, 108, 134
),
(
1, 30, 36, 50, 52, 56, 58, 80, 102, 120,
128, 130, 136, 5, 148, 152, 154, 156, 160, 7,
11, 13, 15, 17, 19, 21, 25, 27, 33, 31
),
(
37, 39, 41, 43, 45, 47, 49, 51, 53, 55,
57, 59, 61, 63, 3, 65, 67, 69, 71, 73,
75, 77, 79, 81, 83, 85, 87, 89, 35,111
),
(
91, 93, 95, 97, 99, 101, 103, 105, 107, 109,
112, 113, 115, 117, 119, 121, 123, 125, 127, 150,
129, 9, 131, 133, 135, 137, 139, 141, 143, 145
)
);
procedure GetEntry(aSection, aLevel: Integer; out aFileName: string; out aFileIndex: Integer; out IsOddTable: Boolean; out aOddIndex: Integer);
protected
procedure DoInitializeLevelSystem; override;
public
// all 6 built in dos styles use the same filename pattern
end;
TDosOhNoStyle = class sealed(TStyle)
protected
function GetLevelSystemClass: TLevelSystemClass; override;
function GetMechanics: TMechanics; override;
end;
TDosOhNoLevelSystem = class(TLevelSystem)
private
type
TDosOhNoLevelOrderTable = array[1..5, 1..20] of Byte; {tame..havoc, 1..20} // raw order
const
{-------------------------------------------------------------------------------
My own little system for OhNo: div 10 = file, mod 10 is index.
So 117 means file 11, index 7.
How did I find out this ??? I think I just compared and compared.
Ohno original does about the same trick based on div 8 I think.
-------------------------------------------------------------------------------}
OhNoTable: TDosOhNoLevelOrderTable = (
// tame 1..8 : 10.0, 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7
// tame 9..16 : 11.0, 11.1, 11.2, 11.3, 11.4, 11.5, 11.6, 11.7
// tame 17..20 : 12.0, 12.1, 12.2, 12.3 (missing in windows)
(
100, 101, 102, 103, 104, 105, 106, 107,
110, 111, 112, 113, 114, 115, 116, 117,
120, 121, 122, 123
),
// crazy 1..8 : 0.1, 1.0, 1.4, 2.0, 2.1, 3.0, 3.1, 3.5 (repaired typo crazy 1: 0.0 to the correct 0.1)
// crazy 9..16 : 5.1, 5.4, 5.7, 6.7, 0.4, 1.5, 1.6, 2.6
// crazy 17..20 : 3.4, 3.7, 4.3, 6,4
(
1, 10, 14, 20, 21, 30, 31, 35,
51, 54, 57, 67, 4, 15, 16, 26,
34, 37, 43, 64
),
// wild 1..8 : 9.2, 7.0, 7.1, 7.2, 7.3, 7.5, 8.6, 0.7
// wild 9..16 : 2.2, 2.5, 3.3, 3.6, 4.0, 4.2, 4.4, 5.0 (repaired typo wild 15: 4.5 to the correct 4.4)
// wild 17..20 : 6.3, 6.5, 6.6, 4.7
(
92,70,71,72,73,75,86,7,
22,25,33,36,40,42,44,50,
63,65,66,47
),
// wicked 1..8 : 9.6, 4.6, 9.0, 9.1, 0.5, 9.4, 6.1, 0.6
// wicked 9..16 : 1.2, 8.7, 4.1, 5.5, 6.0, 6.2, 7.7, 8.1,
// wicked 17..20 : 9.7, 9.3, 8.0, 7.6
(
96,46,90,91,5,94,61,6,
12,87,41,55,60,62,77,81,
97,93,80,76
),
// havoc 1..8 : 7.4, 5.3, 3.2, 2.7, 2.4, 2.3, 5.2, 1.7
// havoc 9..16 : 1.1, 0.3, 0.2, 0.0, 4.5, 8.5, 1.3, 8.2
// havoc 17..20 : 8.3, 5.6, 8.4, 9.5
(
74,53,32,27,24,23,52,17,
11,3,2,0,45,85,13,82,
83,56,84,95
)
);
protected
procedure GetEntry(aSection, aLevel: Integer; out aFileName: string; out aFileIndex: Integer; out IsOddTable: Boolean; out aOddIndex: Integer);
procedure DoInitializeLevelSystem; override;
end;
TDosH93Style = class(TStyle)
protected
function GetLevelSystemClass: TLevelSystemClass; override;
function GetMechanics: TMechanics; override;
end;
TDosH93LevelSystem = class(TLevelSystem)
private
procedure GetEntry(aSection, aLevel: Integer; out aFileName: string; out aFileIndex: Integer; out IsOddTable: Boolean; out aOddIndex: Integer);
protected
procedure DoInitializeLevelSystem; override;
end;
TDosH94Style = class(TStyle)
protected
function GetLevelSystemClass: TLevelSystemClass; override;
function GetMechanics: TMechanics; override;
end;
TDosH94LevelSystem = class(TLevelSystem)
procedure GetEntry(aSection, aLevel: Integer; out aFileName: string; out aFileIndex: Integer; out IsOddTable: Boolean; out aOddIndex: Integer);
protected
procedure DoInitializeLevelSystem; override;
end;
TDosX91Style = class(TStyle)
protected
function GetLevelSystemClass: TLevelSystemClass; override;
function GetMechanics: TMechanics; override;
end;
TDosX91LevelSystem = class(TLevelSystem)
private
class procedure GetEntry(aSection, aLevel: Integer; out aFileName: string; out aFileIndex: Integer; out IsOddTable: Boolean; out aOddIndex: Integer); static;
protected
procedure DoInitializeLevelSystem; override;
end;
TDosX92Style = class(TStyle)
protected
function GetLevelSystemClass: TLevelSystemClass; override;
function GetMechanics: TMechanics; override;
end;
TDosX92LevelSystem = class(TLevelSystem)
private
class procedure GetEntry(aSection, aLevel: Integer; out aFileName: string; out aFileIndex: Integer; out IsOddTable: Boolean; out aOddIndex: Integer); static;
protected
procedure DoInitializeLevelSystem; override;
end;
implementation
{ TDosOrigStyle }
function TDosOrigStyle.GetLevelSystemClass: TLevelSystemClass;
begin
Result := TDosOrigLevelSystem;
end;
function TDosOrigStyle.GetMechanics: TMechanics;
begin
Result := DOSORIG_MECHANICS;
end;
{ TDosOrigLevelSystem }
procedure TDosOrigLevelSystem.GetEntry(aSection, aLevel: Integer; out aFileName: string; out aFileIndex: Integer; out IsOddTable: Boolean; out aOddIndex: Integer);
{-------------------------------------------------------------------------------
I think the numbers in the table are subtracted by 1 before being used in the manner Mike described.
For example, for Fun 1 the number is 147.
Divide by 2 (dropping lowest bit first) and you get 73. "Just Dig" is the 2nd
level in set level009.dat. Using 0-based counting, 73 would indeed be the correct number.
On the other hand, for Fun 8 the number is 14. Divide by 2 and you get 7.
Yet "Turn Around Young Lemmings!" is the 7th
level in set level000.dat. The correct number should be 6 if 0-based counting is used.
This inconsistency goes away if all the numbers are subtracted by 1 first. For example, the 147 becomes 146. Divide by 2
and you still get 73. But for Fun 9, subtract by 1 and you get 13. Divide by 2 and now you get 6, the correct number when
counting from 0. Alternatively, you can add 1 to all numbers for 1-based counting, so that the 147 becomes 148 and 73
becomes 74. But either way, the parity (odd/even) changes when you add/subtract 1, and after that, Mike's description
regarding the bottom bit works correctly.
-------------------------------------------------------------------------------}
var
B: Byte;
Fx: Integer;
begin
B := SectionTable[aSection + 1, aLevel + 1];
Dec(B);
IsOddTable := Odd(B);
B := B div 2;
Fx := (B) div 8;
aFileName := 'LEVEL' + Fx.ToString.PadLeft(3, '0') + '.DAT';
aFileIndex := B mod 8;
aOddIndex := -1;
if IsOddTable then
aOddIndex := B;
end;
procedure TDosOrigLevelSystem.DoInitializeLevelSystem;
const
sectionNames: array[0..3] of string = ('Fun', 'Tricky', 'Taxing', 'Mayhem');
var
section: TSection;
level: TLevelLoadingInformation;
levelFileName: string;
levelFileIndex: Integer;
isOdd: Boolean;
oddIndex: Integer;
iMusic, iSection, iLevel: Integer;
begin
fOddTableFileName := 'oddtable.dat';
iMusic := 1;
for iSection := 0 to 3 do begin
section := TSection.Create(Self);
section.SectionName := sectionNames[iSection];
for iLevel := 0 to 29 do begin
level := TLevelLoadingInformation.Create(section);
GetEntry(section.SectionIndex, level.LevelIndex, {out} levelFileName, {out} levelFileIndex, {out} isOdd, {out} oddIndex);
level.SourceFileName := levelFileName;
level.SectionIndexInSourceFile := levelFileIndex;
level.UseOddTable := isOdd;
level.OddTableIndex := oddIndex;
// tracks 01..21
level.MusicFileName := 'Track_' + LeadZeroStr(iMusic, 2) + '.mod';
Inc(iMusic);
if iMusic > 21 then
iMusic := 1;
end;
end;
end;
{ TDosOhNoStyle }
function TDosOhNoStyle.GetLevelSystemClass: TLevelSystemClass;
begin
Result := TDosOhNoLevelSystem;
end;
function TDosOhNoStyle.GetMechanics: TMechanics;
begin
Result := DOSOHNO_MECHANICS;
end;
{ TDosOhNoLevelSystem }
procedure TDosOhNoLevelSystem.GetEntry(aSection, aLevel: Integer; out aFileName: string; out aFileIndex: Integer; out IsOddTable: Boolean; out aOddIndex: Integer);
var
H, Sec, Lev: Integer;
begin
// Assert((aSection >= 0) and (aSection <= 4));
// Assert((aLevel >= 0) and (aLevel <= 19));
H := OhnoTable[aSection + 1, aLevel + 1];
Sec := H div 10;
Lev := H mod 10;
aFilename := 'Dlvel' + LeadZeroStr(Sec, 3) + '.dat';
aFileIndex := Lev;
IsOddTable := False;
aOddIndex := -1;
end;
procedure TDosOhNoLevelSystem.DoInitializeLevelSystem;
const
sectionNames: array[0..4] of string = ('Tame','Crazy','Wild','Wicked','Havoc');
var
section: TSection;
level: TLevelLoadingInformation;
levelFileName: string;
levelFileIndex: Integer;
isOdd: Boolean;
oddIndex: Integer;
iMusic, iSection, iLevel: Integer;
begin
fOddTableFileName := '';
iMusic := 1;
for iSection := 0 to 4 do begin
section := TSection.Create(Self);
section.SectionName := sectionNames[iSection];
for iLevel := 0 to 19 do begin
level := TLevelLoadingInformation.Create(section);
GetEntry(section.SectionIndex, level.LevelIndex, {out} levelFileName, {out} levelFileIndex, {out} isOdd, {out} oddIndex);
level.SourceFileName := levelFileName;
level.SectionIndexInSourceFile := levelFileIndex;
level.UseOddTable := isOdd;
level.OddTableIndex := oddIndex;
// tracks 01..06
level.MusicFileName := 'Track_' + LeadZeroStr(iMusic, 2) + '.mod';
Inc(iMusic);
if iMusic > 6 then
iMusic := 1;
end;
end;
end;
{ TDosH93Style }
function TDosH93Style.GetLevelSystemClass: TLevelSystemClass;
begin
Result := TDosH93LevelSystem;
end;
function TDosH93Style.GetMechanics: TMechanics;
begin
Result := DOSOHNO_MECHANICS;
end;
{ TDosH93LevelSystem }
procedure TDosH93LevelSystem.GetEntry(aSection, aLevel: Integer; out aFileName: string; out aFileIndex: Integer; out IsOddTable: Boolean; out aOddIndex: Integer);
// I know this can be a oneliner, but this shows better which level is where
begin
IsOddTable := False;
aOddIndex := -1;
Inc(aSection);
Inc(aLevel);
case aSection of
1:
case aLevel of
1..8:
begin
aFileName := 'LEVEL000.DAT';
aFileIndex := aLevel - 1;
end;
9..16 :
begin
aFileName := 'LEVEL001.DAT';
aFileIndex := aLevel - 9;
end;
end;
2:
case aLevel of
1..8 :
begin
aFileName := 'LEVEL002.DAT';
aFileIndex := aLevel - 1;
end;
9..16 :
begin
aFileName := 'LEVEL003.DAT';
aFileIndex := aLevel - 9;
end;
end;
end;
end;
procedure TDosH93LevelSystem.DoInitializeLevelSystem;
// 2 sections with each 16 levels
const
sectionNames: array[0..1] of string = ('Flurry','Blitz');
var
section: TSection;
level: TLevelLoadingInformation;
levelFileName: string;
levelFileIndex: Integer;
isOdd: Boolean;
oddIndex: Integer;
iMusic, iSection, iLevel: Integer;
begin
fOddTableFileName := '';
iMusic := 1;
for iSection := 0 to 1 do begin
section := TSection.Create(Self);
section.SectionName := sectionNames[iSection];
for iLevel := 0 to 15 do begin
level := TLevelLoadingInformation.Create(section);
GetEntry(section.SectionIndex, level.LevelIndex, {out} levelFileName, {out} levelFileIndex, {out} isOdd, {out} oddIndex);
level.SourceFileName := levelFileName;
level.SectionIndexInSourceFile := levelFileIndex;
level.UseOddTable := isOdd;
level.OddTableIndex := oddIndex;
// tracks 01..06
level.MusicFileName := '';//'Track_' + LeadZeroStr(iMusic, 2) + '.mod';
Inc(iMusic);
if iMusic > 6 then
iMusic := 1;
end;
end;
end;
{ TDosH94Style }
function TDosH94Style.GetLevelSystemClass: TLevelSystemClass;
begin
Result := TDosH94LevelSystem;
end;
function TDosH94Style.GetMechanics: TMechanics;
begin
Result := DOSOHNO_MECHANICS;
end;
{ TDosH94LevelSystem }
procedure TDosH94LevelSystem.GetEntry(aSection, aLevel: Integer; out aFileName: string; out aFileIndex: Integer; out IsOddTable: Boolean; out aOddIndex: Integer);
// I know this can be a oneliner, but this shows better which level is where
begin
IsOddTable := False;
aOddIndex := -1;
Inc(aSection);
Inc(aLevel);
case aSection of
1:
case aLevel of
1..8:
begin
aFileName := 'LEVEL000.DAT';
aFileIndex := aLevel - 1;
end;
9..16 :
begin
aFileName := 'LEVEL001.DAT';
aFileIndex := aLevel - 9;
end;
end;
2:
case aLevel of
1..8 :
begin
aFileName := 'LEVEL002.DAT';
aFileIndex := aLevel - 1;
end;
9..16 :
begin
aFileName := 'LEVEL003.DAT';
aFileIndex := aLevel - 9;
end;
end;
3:
case aLevel of
1..8 :
begin
aFileName := 'LEVEL004.DAT';
aFileIndex := aLevel - 1;
end;
9..16 :
begin
aFileName := 'LEVEL005.DAT';
aFileIndex := aLevel - 9;
end;
end;
4:
case aLevel of
1..8 :
begin
aFileName := 'LEVEL006.DAT';
aFileIndex := aLevel - 1;
end;
9..16 :
begin
aFileName := 'LEVEL007.DAT';
aFileIndex := aLevel - 9;
end;
end;
end;
end;
procedure TDosH94LevelSystem.DoInitializeLevelSystem;
// 2 sections with each 16 levels
const
sectionNames: array[0..3] of string = ('Frost ''94','Hail ''94', 'Flurry ''93', 'Blitz ''93');
var
section: TSection;
level: TLevelLoadingInformation;
levelFileName: string;
levelFileIndex: Integer;
isOdd: Boolean;
oddIndex: Integer;
iMusic, iSection, iLevel: Integer;
begin
fOddTableFileName := '';
iMusic := 1;
for iSection := 0 to 3 do begin
section := TSection.Create(Self);
section.SectionName := sectionNames[iSection];
for iLevel := 0 to 15 do begin
level := TLevelLoadingInformation.Create(section);
GetEntry(section.SectionIndex, level.LevelIndex, {out} levelFileName, {out} levelFileIndex, {out} isOdd, {out} oddIndex);
level.SourceFileName := levelFileName;
level.SectionIndexInSourceFile := levelFileIndex;
level.UseOddTable := isOdd;
level.OddTableIndex := oddIndex;
// tracks 01..02
level.MusicFileName := 'Track_' + LeadZeroStr(iMusic, 2) + '.mod';
Inc(iMusic);
if iMusic > 2 then
iMusic := 1;
end;
end;
end;
{ TDosX91Style }
function TDosX91Style.GetLevelSystemClass: TLevelSystemClass;
begin
Result := TDosX91LevelSystem;
end;
function TDosX91Style.GetMechanics: TMechanics;
begin
Result := DOSOHNO_MECHANICS;
end;
{ TDosX91LevelSystem }
class procedure TDosX91LevelSystem.GetEntry(aSection, aLevel: Integer; out aFileName: string; out aFileIndex: Integer; out IsOddTable: Boolean; out aOddIndex: Integer);
begin
aFileName := 'LEVEL000.DAT';
aFileIndex := aLevel;
IsOddTable := False;
aOddIndex := -1;
end;
procedure TDosX91LevelSystem.DoInitializeLevelSystem;
// one section with 4 levels
var
section: TSection;
level: TLevelLoadingInformation;
levelFileName: string;
levelFileIndex: Integer;
isOdd: Boolean;
oddIndex: Integer;
iMusic, iLevel: Integer;
begin
fOddTableFileName := '';
iMusic := 1;
section := TSection.Create(Self);
section.SectionName := 'XMas';
for iLevel := 0 to 3 do begin
level := TLevelLoadingInformation.Create(section);
GetEntry(section.SectionIndex, level.LevelIndex, {out} levelFileName, {out} levelFileIndex, {out} isOdd, {out} oddIndex);
level.SourceFileName := levelFileName;
level.SectionIndexInSourceFile := levelFileIndex;
level.UseOddTable := isOdd;
level.OddTableIndex := oddIndex;
// not tracks yet
level.MusicFileName := '';
Inc(iMusic);
if iMusic > 6 then
iMusic := 1;
end;
end;
{ TDosX92Style }
function TDosX92Style.GetLevelSystemClass: TLevelSystemClass;
begin
Result := TDosX92LevelSystem;
end;
function TDosX92Style.GetMechanics: TMechanics;
begin
Result := DOSOHNO_MECHANICS;
end;
{ TDosX92LevelSystem }
class procedure TDosX92LevelSystem.GetEntry(aSection, aLevel: Integer; out aFileName: string; out aFileIndex: Integer; out IsOddTable: Boolean; out aOddIndex: Integer);
begin
aFileName := 'LEVEL000.DAT';
aFileIndex := aLevel;
IsOddTable := False;
aOddIndex := -1;
end;
procedure TDosX92LevelSystem.DoInitializeLevelSystem;
// one section with 4 levels
var
section: TSection;
level: TLevelLoadingInformation;
levelFileName: string;
levelFileIndex: Integer;
isOdd: Boolean;
oddIndex: Integer;
iMusic, iLevel: Integer;
begin
fOddTableFileName := '';
iMusic := 1;
section := TSection.Create(Self);
section.SectionName := 'XMas';
for iLevel := 0 to 3 do begin
level := TLevelLoadingInformation.Create(section);
GetEntry(section.SectionIndex, level.LevelIndex, {out} levelFileName, {out} levelFileIndex, {out} isOdd, {out} oddIndex);
level.SourceFileName := levelFileName;
level.SectionIndexInSourceFile := levelFileIndex;
level.UseOddTable := isOdd;
level.OddTableIndex := oddIndex;
// not tracks yet
level.MusicFileName := '';
Inc(iMusic);
if iMusic > 6 then
iMusic := 1;
end;
end;
end.