-
Notifications
You must be signed in to change notification settings - Fork 1
/
TFKEntries.pas
691 lines (621 loc) · 18.8 KB
/
TFKEntries.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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
unit TFKEntries;
(***************************************)
(* TFK Entries for GAMEversion 1.0.1.7*)
(***************************************)
(* Created by Neoff *)
(* mail : [email protected] *)
(* site : http://tfk.mirgames.ru *)
(***************************************)
interface
uses MyEntries, Engine_Reg, Graph_Lib, Func_Lib, MapObj_Lib, ItemObj_Lib, ObjAnim_Lib, demo_lib,
LightMap_Lib, Scenario_Lib, WP_Lib, Constants_Lib;
const
defHead : TMapHeader1=
(MapType: 'TFKM'; ECount:1; Version:1; Author:'TFK'; Name: 'TFKMap';gametype: GT_FFA+GT_RAIL+GT_TDM);
type
TBrick= word;//2 bytes íà îäèí áðèê. ïåðâûé - ñàì áðèê. âòîðîé - ïðîõîäèì ëè áðèê :)
//0 - áðèê ïðîõîäèì âñåãäà
const
MASK_BLOCK = 1;
MASK_FRONT = 2;
MASK_CONTAINER = 4; //çàõâà÷åí ëèôòîì!
MASK_OBJ = 8;
MASK_WATER = 16;
MASK_LAVA = 32;
type
TBricksEntry =
class(TSimpleEntry)
constructor Create(Head_: TEntryHead; var F: File);overload;
constructor Create(Width_, Height_: integer);overload;
protected
tempbuf: array of byte;
function GetHeight: integer;
function GetWidth: integer;
function GetBricks(x, y: integer): word;
procedure SetBricks(x, y: integer; const Value: word);
function GetMask(x, y: integer): byte;
procedure SetMask(x, y: integer; const Value: byte);
function GetHead: TEntryHead;override;
public
class function EntryClassName: TEntryClassName;
property Brick[x, y: integer]:word read GetBricks write SetBricks;default;
property Mask[x, y: integer]: byte read GetMask write SetMask;
property Width: integer read GetWidth;
property Height: integer read GetHeight;
procedure Clear;
procedure SetSize(newWidth, newHeight: integer);
end;
/////
TMapObjEntry =
class(TSimpleEntry)
constructor Create(Head_: TEntryHead; var F: File);overload;
constructor Create;overload;
private
function GetObj(i: integer): TCustomMapObj;
procedure SetObj(i: integer; const Value: TCustomMapObj);
function GetGObj(i: integer): TGeometryObj;
protected
freeplace: integer;
objs: array of TCustomMapObj;
gobjs: array of TGeometryObj;
public
is_monsters: boolean;
mintrainwidth, mintrainheight: integer;
Triggers: array of TCustomTrigger;
TrainPoints: array of TTrainPointObj;
liquids: array of TCustomLiquid;
class function EntryClassName: TEntryClassName;
procedure RestartObjects;
function GetTrainPoint(index: integer): TTrainPointObj;
function Count: integer;
function g_Count: integer;
function trig_Count: integer;
property Obj[i: integer]: TCustomMapObj read GetObj write SetObj;default;
property g_Obj[i: integer]: TGeometryObj read GetGObj;
function CreateSpecObj(struct: TMapObjStruct):TCustomMapObj;virtual;
function Add(struct: TMapObjStruct):TCustomMapObj;virtual;
procedure SetSize(newlength: integer);
end;
{ function TStringEntry =
class(TCustomEntry)
constructor Create(Head_: TEntryHead; var F: File);overload;
constructor Create;overload;
public
class function EntryClassName: TEntryClassName;
function GetStrByIndex();
end;}
////////////////////
TTFKMap = class(TCustomMap)
private
function GetHeight: word;
function GetWidth: word;
public
//
Brk : TBricksEntry;
BrkTex : TBricksTexEntry;//ïðèãîäèòñÿ ïîòîì....
Obj : TMapObjEntry;
Lights : TLightsEntry;
LightMap: TLightMapEntry;
Demo : TTFKDemo;
WP : TWPEntry;
//ðåñïàóíû
respawns: array of TRespawn;
respcount: integer;
nextresp: integer;
teamnextresp: array [0..2] of integer;
t_triggers: array [0..10000] of boolean;
t_count: integer;
procedure Clear;override;
procedure NewMap;virtual;
procedure AfterLoad;override;
procedure BeforeLoad; override;
function CreateEntry(head: TEntryHead; var f: File): TCustomEntry;override;
property Width : Word read GetWidth;
property Height : Word read GetHeight;
end;
implementation
uses NFKBrick_Lib;
{ TBricksEntry }
procedure TBricksEntry.Clear;
begin
buf:=nil;
tempbuf:=nil;
fhead.size:=0;
fhead.maxx:=0;
fhead.maxy:=0;
end;
constructor TBricksEntry.Create(Head_: TEntryHead; var F: File);
var
i, j: integer;
begin
inherited Create(Head_, F);
if head_.version=1 then
begin
for i:=0 to Width-1 do
for j:=0 to Height-1 do
Mask[i, j]:=ord(Brick[i, j]>0);
end else
for i:=0 to Width-1 do
for j:=0 to Height-1 do
Mask[i, j]:=Mask[i, j] and (MASK_BLOCK or MASK_FRONT);
end;
constructor TBricksEntry.Create(Width_, Height_: integer);
begin
inherited Create;
SetSize(Width_, Height_);
end;
class function TBricksEntry.EntryClassName: TEntryClassName;
begin
Result:='BricksV1';
end;
function TBricksEntry.GetBricks(x, y: integer): word;
begin
if (x>=0) and (x<fhead.maxx) and
(y>=0) and (y<fhead.maxy) then
Result:=word(buf[(y*width+x)*SizeOf(TBrick)])
else Result:=fhead.defaultBrick;
end;
function TBricksEntry.GetHead: TEntryHead;
begin
fhead.EntryClass:=EntryClassName;
fhead.version:=2;
Result:=fhead;
end;
function TBricksEntry.GetHeight: integer;
begin
Result:=head.maxy;
end;
function TBricksEntry.GetMask(x, y: integer): byte;
begin
if (x>=0) and (x<width) and
(y>=0) and (y<height) then
Result:=buf[(y*width+x)*SizeOf(TBrick)+1]
else Result:=MASK_BLOCK;
end;
function TBricksEntry.GetWidth: integer;
begin
Result:=head.maxx;
end;
procedure TBricksEntry.SetBricks(x, y: integer; const Value: word);
begin
if (x>=0) and (x<width) and
(y>=0) and (y<height) then
buf[(y*width+x)*SizeOf(TBrick)]:=value and 255;
end;
procedure TBricksEntry.SetSize(newWidth, newHeight: integer);
var
n: cardinal;
begin
buf:=nil;
fhead.maxx:=newWidth;
fhead.maxy:=newHeight;
n:=SizeOf(TBrick)*newWidth*newHeight;
SetBufSize(n);
end;
procedure TBricksEntry.SetMask(x, y: integer; const Value: byte);
begin
if (x>=0) and (x<width) and
(y>=0) and (y<height) then
buf[(y*width+x)*SizeOf(TBrick)+1]:=value;
end;
{ TMapObjEntry }
procedure TMapObjEntry.RestartObjects;
var
i: integer;
begin
for i:=0 to Count-1 do
Obj[i].restart;
end;
function TMapObjEntry.Count: integer;
begin
Result := High(Objs) + 1;
end;
constructor TMapObjEntry.Create(Head_: TEntryHead; var F: File);
var
i, j, k, l : integer;
struct : PMapObjStruct;
begin
inherited Create(head_, F);
is_monsters:=false;
mintrainwidth:=0;
mintrainheight:=0;
SetLength(objs, head.size div SizeOf(TMapObjStruct));
SetLength(gobjs, head.size div SizeOf(TMapObjStruct));
SetLength(liquids, head.size div SizeOf(TMapObjStruct));
j:=0;k:=0;l:=0;
for i:=0 to Count-1 do
begin
struct:=@buf[i*SizeOf(TMapObjStruct)];
if ObjGameMask(struct^) and gametype>0 then
begin
objs[j]:=CreateSpecObj(struct^);
if (objs[j] is TGeometryObj) then
begin
gobjs[k]:=TGeometryObj(objs[j]);
Inc(k);
end;
if (objs[i] is TAreaTeleportWay) then
begin
SetLength(Triggers, trig_Count+1);
Triggers[high(Triggers)]:=TCustomTrigger(objs[i]);
end;
if (objs[i] is TTrainObj) then
begin
if mintrainwidth<obj[i].width then
mintrainwidth:=obj[i].width;
if mintrainheight<obj[i].height then
mintrainheight:=obj[i].height;
end;
if (objs[i] is TTrainPointObj) then
begin
SetLength(TrainPoints, length(TrainPoints)+1);
TrainPoints[high(TrainPoints)]:=TTrainPointObj(objs[i]);
end;
if (objs[j] is TCustomLiquid) then
begin
liquids[l]:=TCustomLiquid(Objs[j]);
Inc(l);
end;
if (objs[i] is TMonsterObj) then
begin
Is_Monsters:=true;
end;
Inc(j);
end;
end;
SetLength(objs, j);
SetLength(gobjs, k);
SetLength(liquids, l);
end;
constructor TMapObjEntry.Create;
begin
inherited Create;
freeplace:=0;
end;
function TMapObjEntry.CreateSpecObj(struct: TMapObjStruct): TCustomMapObj;
begin
case struct.objtype of
otNone:
Result:=TCustomMapObj.Create(struct);
otRespawn:
Result:=TRespawn.Create(struct);
otPortal:
Result:=TPortal.create(struct);
otTeleport:
Result:=TTeleport.create(struct);
otButton:
Result:=TButton.Create(struct);
otNFKDoor:
Result:=TNFKDoor.Create(struct);
otTrigger:
Result:=TTrigger.Create(struct);
otJumpPad:
Result:=TJumpPad.create(struct);
otArmor:
Result:=TArmorObj.Create(struct);
otHealth:
Result:=THealthObj.Create(struct);
otWeapon:
Result:=TWeaponObj.Create(struct);
otAmmo:
Result:=TAmmoObj.Create(struct);
otPowerUp:
result:=TPowerUpObj.Create(struct);
otDeathLine:
result:=TDeathLineObj.Create(struct);
otElevator:
result:=TElevatorObj.Create(struct);
otTriangle:
result:=TTriangleObj.Create(struct);
otAreaPain:
result:=TAreaPain.Create(struct);
otAreaPush:
result:=TAreaPush.Create(struct);
otArenaEnd:
result:=TArenaEnd.Create(struct);
otAreaTeleport:
result:=TAreaTeleport.Create(struct);
otTeleportWay:
result:=TAreaTeleportWay.Create(struct);
otEmptyBricks:
Result:=TCustomMapObj.Create(struct);
// result:=TEmptyBricks.Create(struct);
otBackBricks:
Result:=TCustomMapObj.Create(struct);
// result:=TBackBricks.Create(struct);
otLightLine:
result:=TLightLineObj.Create(struct);
otBloodGen:
result:=TBloodGen.Create(struct);
otWater:
result:=TWaterObj.Create(struct);
otLava:
result:=TLavaObj.Create(struct);
otWeather:
result:=TWeather.Create(struct);
otTrain:
result:=TTrainObj.Create(struct);
otTrainPoint:
result:=TTrainPointObj.Create(struct);
otBelt:
result:=TBelt.Create(struct);
otAnimation:
result:=TAnimationObj.Create(struct);
otSoundTrigger:
result:=TSoundTrigger.Create(struct);
otDestroyer:
result:=TDestroyerObj.Create(struct);
otMonster:
result:=TMonsterObj.Create(struct);
else Result:=TCustomMapObj.Create(struct);
end;
end;
function TMapObjEntry.GetObj(i: integer): TCustomMapObj;
begin
if (i>=0) and (i<=high(Objs)) then
Result:=Objs[i] else Result:=nil;
end;
procedure TMapObjEntry.SetObj(i: integer; const Value: TCustomMapObj);
begin
if (i>=0) and (i<=high(Objs)) then
Objs[i]:=Value;
end;
procedure TMapObjEntry.SetSize(newlength: integer);
begin
if freeplace>=newlength then
freeplace:=newlength-1;
SetLength(Objs, newLength);
end;
class function TMapObjEntry.EntryClassName: TEntryClassName;
begin
Result:='ObjectsV1';
end;
function TMapObjEntry.Add(struct: TMapObjStruct): TCustomMapObj;
begin
//ïîèñê ñâîáîäíîãî ìåñòà
if freeplace=Length(objs)-1 then
freeplace:=0;
while (freeplace<Length(objs)) and (Objs[freeplace]<>nil) do
Inc(freeplace);
if freeplace>=Length(objs) then
SetSize(Length(objs)+1);
Objs[freeplace]:=CreateSpecObj(struct);
Result:=Objs[freeplace];
end;
function TMapObjEntry.g_Count: integer;
begin
Result:=length(gObjs);
end;
function TMapObjEntry.GetGObj(i: integer): TGeometryObj;
begin
if (i>=0) and (i<=high(gObjs)) then
Result:=gObjs[i] else Result:=nil;
end;
function TMapObjEntry.trig_Count: integer;
begin
if Triggers<>nil then Result:=length(Triggers)
else Result:=0;
end;
function TMapObjEntry.GetTrainPoint(index: integer): TTrainPointObj;
var
i: integer;
begin
Result:=nil;
for i:=low(trainpoints) to high(trainpoints) do
if trainpoints[i].index=index then
begin
Result:=trainpoints[i];
Break;
end;
end;
{ TTFKMap }
procedure TTFKMap.Clear;
begin
inherited Clear;
fhead:=defHead;
end;
procedure TTFKMap.AfterLoad;
var
i, j, k: integer;
procedure addtrig(x: integer);
begin
if (x>0) and (x<9999) then
if not t_triggers[x] then
begin
t_triggers[x]:=true;
Inc(t_count);
end;
end;
begin
if Brk=nil then
Brk:=TBricksEntry.Create(20, 30);
if Obj=nil then
Obj:=TMapObjEntry.Create;
t_count:=0;
for i:=0 to Obj.Count-1 do
begin
AddTrig(Obj[i].Target);
AddTrig(Obj[i].struct.target_name);
if Obj[i].objtype=otElevator then
begin
AddTrig(Obj[i].Struct.etarget1);
AddTrig(Obj[i].Struct.etarget2);
AddTrig(Obj[i].Struct.etargetname1);
AddTrig(Obj[i].Struct.etargetname2);
end;
end;
//èñáàâëÿåìñÿ îò back-áðèê îáúåêòîâ
k:=0;
with Obj do
while k<Count do
begin
with Obj[k] do
if ObjType = otBackBricks then
begin
for i:=struct.x to struct.x+struct.width-1 do
for j:=struct.y to struct.y+struct.height-1 do
Brk.Mask[i, j]:=2*ord(struct.plane>0);
end else
if ObjType = otEmptyBricks then
begin
for i:=x to x+width-1 do
for j:=y to y+height-1 do
Brk.Mask[i, j]:=Brk.Mask[i, j] or MASK_BLOCK;
end else if Obj[k] is TCustomLiquid then
begin
{ for i:=x to x+width-1 do
for j:=y to y+height-1 do
Brk.Mask[i, j]:=Brk.Mask[i, j] or MASK_WATER;
if Obj[k] is TLavaObj then
for i:=x to x+width-1 do
for j:=y to y+height-1 do
Brk.Mask[i, j]:=Brk.Mask[i, j] or MASK_LAVA;}
end;
inc(k);
end;
nfk_BricksInit;
//èùåì ðåñïàóíû...
j:=0;
for i:=0 to Obj.Count-1 do
if (Obj[i] is TRespawn) then
Inc(j);
respawns:=nil;
if j>0 then
begin
respcount:=j;
SetLength(respawns, j);
j:=0;
for i:=0 to Obj.Count-1 do
if (Obj[i] is TRespawn) then
begin
respawns[j]:=TRespawn(Obj[i]);
Obj[i].tag:=j;
Inc(j);
end;
nextresp:=random(j);
end else
begin
respcount:=0;
SetLength(respawns, 1);
respawns[0]:=TRespawn.Create(ObjStruct(otRespawn, Width div 2, Height div 2, 1, 1));
Obj.SetSize(Obj.Count+1);
Obj[Obj.Count-1]:=respawns[0];
nextresp:=0;
end;
//çàïîìèíàíèå ñòàðòîâîãî ðåêòà
for i:=0 to Obj.Count-1 do
Obj[i].StartRect:=Obj[i].ObjRect;
//çàõâàò ëèôòîì èòåìîâ
for j:=0 to Obj.Count-1 do
if Obj[j] is TElevatorObj then
for i:=0 to Obj.Count-1 do
begin
if (Obj[i].ObjType in ChildObjects) and
(Obj[i].x>=Obj[j].x) and (Obj[i].x+Obj[i].Width<=Obj[j].x+Obj[j].width) and
(Obj[i].y>=Obj[j].y) and (Obj[i].y+Obj[i].Height<=Obj[j].y+Obj[j].height) then
Obj[i].fOwner:=Obj[j];
// else
if (Obj[i].ObjType in [otPortal, otTeleport, otAreaTeleport, otTeleportWay]) and
(Obj[i].struct.gotox>=Obj[j].x) and (Obj[i].struct.gotox+Obj[i].Width<=Obj[j].x+Obj[j].width) and
(Obj[i].struct.gotoy>=Obj[j].y) and (Obj[i].struct.gotoy+Obj[i].Height<=Obj[j].y+Obj[j].height) then
Obj[i].fOwner2:=Obj[j];
end;
//çàõâàò áðèêîâ ëèôòàìè
for j:=0 to Obj.Count-1 do
if Obj[j] is TBricksObj then
TBricksObj(Obj[j]).TakeBricks;
//çàõâàò áðèêîâ äåñòðîéåðàìè
for j:=0 to Obj.Count-1 do
if Obj[j] is TDestroyerObj then
TDestroyerObj(Obj[j]).TakeBricks;
end;
function TTFKMap.GetHeight: Word;
begin
Result:=Brk.Height;
end;
function TTFKMap.GetWidth: Word;
begin
Result:=Brk.Width;
end;
procedure TTFKMap.NewMap;
begin
BeforeLoad;
Clear;
AfterLoad;
end;
function TTFKMap.CreateEntry(head: TEntryHead; var f: File): TCustomEntry;
begin
//ïî entryclassname ñìîòðèò êîãî æå ñîçäàòü :)
//íå çàáóäüòå
if (head.EntryClass=TBricksEntry.EntryClassName) then
if TBricksEntry.IsValidVersion(head.version) then
begin
Brk:=TBricksEntry.Create(head, f);
Result:=Brk;
end
else Result:=TSimpleEntry.Create(head, f)
else if (head.EntryClass=TMapObjEntry.EntryClassName) then
if TMapObjEntry.IsValidVersion(head.version) then
begin
Obj:=TMapObjEntry.Create(head, f);
Result:=Obj;
end
else Result:=TSimpleEntry.Create(head, f)
else if (head.EntryClass=TBricksTexEntry.EntryClassName) then
if TBricksTexEntry.IsValidVersion(head.version) then
begin
BrkTex:=TBricksTexEntry.Create(head, f);
Result:=BrkTex;
end
else Result:=TSimpleEntry.Create(head, f)
else if (head.EntryClass=TLightsEntry.EntryClassName) then
if TLightsEntry.IsValidVersion(head.version) then
begin
Lights:=TLightsEntry.Create(head, f);
Result:=Lights;
end
else Result:=TSimpleEntry.Create(head, f)
else if (head.EntryClass=TLightMapEntry.EntryClassName) then
if TLightMapEntry.IsValidVersion(head.version) then
begin
LightMap:=TLightMapEntry.Create(head, f);
Result:=LightMap;
end
else Result:=TSimpleEntry.Create(head, f)
else if (head.EntryClass=TWPEntry.EntryClassName) then
if TWPEntry.IsValidVersion(head.version) then
begin
WP:=TWPEntry.Create(head, f);
Result:=WP;
end
else Result:=TSimpleEntry.Create(head, f)
else if (head.EntryClass=TTFKDemo.EntryClassName) then
if TTFKDemo.IsValidVersion(head.version) then
begin
Demo:=TTFKDemo.Create(head, f);
Result:=Demo;
end
else
begin
Log('^1INVALID DEMO VERSION: ^3'+IntToStr(head.version));
Result:=nil;
end
else if (head.EntryClass=TTFKScenario.EntryClassName) then
if TTFKScenario.IsValidVersion(head.version) then
Result:=TTFKScenario.Create(head, f)
else
begin
Log('^1INVALID SCENARIO VERSION: ^3'+IntToStr(head.version));
Result:=nil;
end
else Result:=TSimpleEntry.Create(head, f);
end;
procedure TTFKMap.BeforeLoad;
begin
Brk:=nil;Obj:=nil;Demo:=nil;
BrkTex:=nil;
Lights:=nil;
LightMap:=nil;
WP:=nil;
end;
end.