-
Notifications
You must be signed in to change notification settings - Fork 4
/
mapcore.pas
857 lines (709 loc) · 21.8 KB
/
mapcore.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
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
unit mapcore;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
Const
MaxListSize = 100;
ZSizeDefaults : array of integer = (8,16,32,64,128,256);
DefMaxMapWidth = 256;
DefMaxMapHeight = 256;
RMMapSig = 'RMM';
RMMapVersion = 2;
TileClear = -1;
TileMissing = -2;
type
TileRec = packed Record
ImageUID : TGUID;
ImageIndex : integer;
end;
MapClipBoardRec = Record
width,height : integer; //width of copy / paste buffer
Status : integer; // 1 = data has been copied to buffer - do not paste if status is 0
Tile : array[0..255,0..255] of TileRec;
end;
MapHeaderRec = packed Record
SIG : array[1..3] of char;
version : word;
MapCount : word;
end;
MapClipAreaRec = Record
x,y,x2,y2 : integer;
status : integer;
end;
MapScrollPosRec = Record
HorizPos : integer;
VirtPos : integer;
end;
MapPropsRec = packed Record
width : integer;
height : integer;
tilewidth : integer;
tileheight : integer;
ZoomTilewidth : integer;
ZoomTileheight : integer;
ZoomSize : integer;
DrawTool : integer;
TileMode : integer;
GridStatus : integer; //0 = 0ff - 1=on
ClipArea : MapClipAreaRec;
ScrollPos : MapScrollPosRec;
end;
MapExportFormatRec = Packed Record
Name : String[20]; // user = RES file used in name/description, in Text output used in array name, for palettes we add pal to name
Lan : integer; // auto -ahould be for what compiler eg PascalLan,BasicLan,CLan
MapFormat : integer; // user - 0 = do not export, Map Format, 1 = Simple format
Width : integer; // map width overwrite - if not 0 use this value as width
Height : integer; // map height overwrite - if not 0 use this value as height
end;
MapRec = packed Record
Props : MapPropsRec;
ExportProps : MapExportFormatRec;
Tile : array of array of TileRec;
end;
TMapCoreBase = Class
Map : array of MapRec;
UndoMap : array of MapRec;
ClipBoard : MapClipBoardRec;
CurrentMap : integer;
MapCount : integer;
constructor Create;
procedure Init;
procedure SetListSize(size : integer);
procedure SetMapSize(index, mwidth,mheight : integer);
procedure ResizeMapSize(index, mwidth,mheight : integer);
procedure SetMapTileSize(index, twidth,theight : integer);
procedure SetZoomMapTileSize(index, twidth,theight : integer);
procedure SetMapScrollVertPos(index, value : integer);
function GetMapScrollVertPos(index : integer) : integer;
procedure SetMapScrollHorizPos(index, value : integer);
function GetMapScrollHorizPos(index : integer) : integer;
procedure SetMapDrawTool(index, value : integer);
function GetMapDrawTool(index : integer) : integer;
procedure SetMapGridStatus(index, value : integer);
function GetMapGridStatus(index : integer) : integer;
procedure SetMapClipStatus(index,mode : integer);
function GetMapClipStatus(index : integer) : integer;
procedure GetMapClipAreaCoords(index : integer;var ca : MapClipAreaRec);
procedure SetMapClipAreaCoords(index : integer;var ca : MapClipAreaRec);
procedure SetMapTileMode(index, value : integer);
function GetMapTileMode(index : integer) : integer;
Procedure Hflip(index,x,y,x2,y2: integer);
Procedure VFlip(index,x,y,x2,y2 : integer);
Procedure ScrollLeft(index,x,y,x2,y2 : integer);
Procedure ScrollRight(index,x,y,x2,y2 : integer);
Procedure ScrollUp(index,x,y,x2,y2 : integer);
Procedure ScrollDown(index,x,y,x2,y2 : integer);
Procedure CopyToUndo(index : integer);
Procedure Undo(index : integer);
procedure GetMapProps(index : integer;var props : MapPropsRec);
procedure SetMapProps(index : integer; props : MapPropsRec);
function GetExportHeight(index : integer) : integer;
function GetExportWidth(index : integer) : integer;
function GetExportName(index : integer) : string;
function GetExportMapCount : integer;
procedure GetMapExportProps(index : integer;var props : MapExportFormatRec);
procedure SetMapExportProps(index : integer; props : MapExportFormatRec);
procedure ClearExportProperties(index : integer);
function GetMapWidth(index : integer) : integer;
function GetMapHeight(index : integer) : integer;
function GetMapPageWidth(index : integer) : integer; // in pixels
function GetMapPageHeight(index : integer) : integer; // in pixels
function GetZoomMapPageWidth(index : integer) : integer; // in pixels
function GetZoomMapPageHeight(index : integer) : integer; // in pixels
function GetMapTileWidth(index : integer) : integer;
function GetMapTileHeight(index : integer) : integer;
function GetMapTileIndex(index,x,y : integer) : integer;
function GetZoomMapTileWidth(index : integer) : integer;
function GetZoomMapTileHeight(index : integer) : integer;
function GetZoomTileSize(ZoomSize : integer) : integer;
procedure SetMapTile(index,x,y : integer;var Tile : TileRec);
procedure GetMapTile(index,x,y : integer;var Tile : TileRec);
procedure InitClipBoard;
procedure CopyToClipBoard(index,x,y,x2,y2 : integer);
procedure PasteFromClipBoard(index,x,y,x2,y2 : integer);
procedure SetCurrentMap(index : integer);
function GetCurrentMap : integer;
function GetMapCount : integer;
procedure SetMapCount(count : integer);
procedure DeleteMap(index : integer);
procedure InsertMap(index : integer);
procedure AddMap;
procedure CloneMap;
procedure SetZoomSize(index,size : integer);
function GetZoomSize(index : integer) : integer;
procedure ClearMap(index,value : integer);
function IsMapCustomSize(index : integer) : boolean;
end;
var
MapCoreBase : TMapCoreBase;
implementation
constructor TMapCoreBase.Create;
begin
Init;
end;
procedure TMapCoreBase.Init;
begin
SetCurrentMap(0);
SetListSize(MaxListSize);
SetZoomSize(0,4);
// SetMapSize(0,DefMaxMapWidth,DefMaxMapHeight);
SetMapSize(0,16,16);
SetMapTileSize(0,64,64);
SetMapCount(1);
SetMapGridStatus(0,1); //grid on
SetMapClipStatus(0,0); //clip off
SetMapDrawTool(0,1); //pencil
SetMapTileMode(0,1); //draw
SetMapScrollVertPos(0,0);
SetMapScrollHorizPos(0,0);
CopyToUndo(0); //copy map 0 to undo - to init it
InitClipBoard;
end;
procedure TMapCoreBase.SetListSize(size : integer);
begin
Setlength(Map,size);
Setlength(UndoMap,size);
end;
Procedure TMapCoreBase.CopyToUndo(index : integer);
var
i,j : integer;
begin
for i:=0 to Map[index].Props.width-1 do
begin
for j:=0 to Map[index].Props.height-1 do
begin
UndoMap[index].Tile[i,j]:=Map[index].Tile[i,j];
end;
end;
end;
Procedure TMapCoreBase.Undo(index : integer);
var
i,j : integer;
TTile : TileRec;
begin
for i:=0 to Map[index].Props.width-1 do
begin
for j:=0 to Map[index].Props.height-1 do
begin
TTile:=Map[index].Tile[i,j];
Map[index].Tile[i,j]:=UndoMap[index].Tile[i,j];
UndoMap[index].Tile[i,j]:=TTile;
end;
end;
end;
procedure TMapCoreBase.InitClipBoard;
begin
ClipBoard.Status:=0;
end;
procedure TMapCoreBase.CopyToClipBoard(index,x,y,x2,y2 : integer);
var
i,j : integer;
width,height : integer;
begin
width:=abs(x2-x+1);
if width > 256 then width:=256;
height:=abs(y2-y+1);
if height > 256 then height:=256;
for i:=0 to width-1 do
begin
for j:=0 to height-1 do
begin
ClipBoard.Tile[i,j]:=Map[index].Tile[x+i,y+j];
end;
end;
ClipBoard.width:=width;
ClipBoard.height:=height;
ClipBoard.Status:=1;
end;
procedure TMapCoreBase.PasteFromClipboard(index,x,y,x2,y2 : integer);
var
i,j : integer;
width,height : integer;
begin
if ClipBoard.Status = 0 then exit;
width:=abs(x2-x+1);
if ClipBoard.width < width then width:=ClipBoard.width;
height:=abs(y2-y+1);
if ClipBoard.height < height then height:=ClipBoard.height;
for i:=0 to width-1 do
begin
for j:=0 to height-1 do
begin
Map[index].Tile[i+x,j+y]:=ClipBoard.Tile[i,j];
end;
end;
end;
procedure TMapCoreBase.SetZoomSize(index,size : integer);
begin
Map[index].Props.ZoomSize:=size;
end;
function TMapCoreBase.GetZoomSize(index : integer) : integer;
begin
GetZoomSize:=Map[index].Props.ZoomSize;
end;
procedure TMapCoreBase.GetMapExportProps(index : integer;var props : MapExportFormatRec);
begin
props:=Map[index].ExportProps;
end;
procedure TMapCoreBase.SetMapExportProps(index : integer; props : MapExportFormatRec);
begin
Map[index].ExportProps:=props;
end;
function TMapCoreBase.GetExportMapCount : integer;
var
i : integer;
Exportcount : integer;
begin
ExportCount:=0;
for i:=0 to GetMapCount-1 do
begin
if Map[i].ExportProps.MapFormat > 0 then inc(ExportCount);
end;
GetExportMapCount:=ExportCount;
end;
//if there is a custom width property (not 0) and less then props width
function TMapCoreBase.GetExportWidth(index : integer) : integer;
var
width : integer;
begin
Width:=Map[index].Props.Width;
if (Map[index].ExportProps.Width > 0) AND (Map[index].ExportProps.Width < Map[index].Props.Width) then
begin
Width:=Map[index].ExportProps.Width;
end;
GetExportWidth:=Width;
end;
//if there is a custom height property (not 0) and less then props height
function TMapCoreBase.GetExportHeight(index : integer) : integer;
var
height : integer;
begin
Height:=Map[index].Props.Height;
if (Map[index].ExportProps.Height > 0) AND (Map[index].ExportProps.Height < Map[index].Props.Height) then
begin
Height:=Map[index].ExportProps.Height;
end;
GetExportHeight:=Height;
end;
function TMapCoreBase.GetExportName(index : integer) : string;
begin
result:=Map[index].ExportProps.Name;
end;
procedure TMapCoreBase.ClearExportProperties(index : integer);
begin
Map[index].ExportProps.MapFormat:=0;
Map[index].ExportProps.Lan:=0;
Map[index].ExportProps.width:=0;
Map[index].ExportProps.height:=0;
Map[index].ExportProps.name:='Map'+IntToStr(index+1);
end;
procedure TMapCoreBase.SetMapSize(index, mwidth,mheight : integer);
begin
Map[index].Props.width:=mwidth;
Map[index].Props.height:=mheight;
ClearExportProperties(index);
SetLength(Map[index].Tile,DefMaxMapWidth,DefMaxMapHeight);
SetLength(UndoMap[index].Tile,DefMaxMapWidth,DefMaxMapHeight);
ClearMap(index,TileClear);
end;
procedure TMapCoreBase.ResizeMapSize(index, mwidth,mheight : integer);
begin
Map[index].Props.width:=mwidth;
Map[index].Props.height:=mheight;
end;
procedure TMapCoreBase.SetMapScrollVertPos(index, value : integer);
begin
Map[index].Props.ScrollPos.VirtPos:=value;
end;
function TMapCoreBase.GetMapScrollVertPos(index : integer) : integer;
begin
result:=Map[index].Props.ScrollPos.VirtPos;
end;
procedure TMapCoreBase.SetMapTileMode(index, value : integer);
begin
Map[index].Props.TileMode:=value;
end;
function TMapCoreBase.GetMapTileMode(index : integer) : integer;
begin
result:=Map[index].Props.TileMode;
end;
procedure TMapCoreBase.SetMapScrollHorizPos(index, value : integer);
begin
Map[index].Props.ScrollPos.HorizPos:=value;
end;
function TMapCoreBase.GetMapScrollHorizPos(index : integer) : integer;
begin
result:=Map[index].Props.ScrollPos.HorizPos;
end;
procedure TMapCoreBase.SetMapDrawTool(index, value : integer);
begin
Map[index].Props.DrawTool:=value;
end;
function TMapCoreBase.GetMapDrawTool(index : integer) : integer;
begin
result:=Map[index].Props.DrawTool;
end;
procedure TMapCoreBase.SetMapGridStatus(index, value : integer);
begin
Map[index].Props.GridStatus:=value;
end;
function TMapCoreBase.GetMapGridStatus(index : integer) : integer;
begin
result:=Map[index].Props.GridStatus;
end;
procedure TMapCoreBase.SetMapClipStatus(index,mode : integer);
begin
Map[index].Props.ClipArea.status:=mode;
end;
function TMapCoreBase.GetMapClipStatus(index : integer) : integer;
begin
result:=Map[index].Props.ClipArea.status;
end;
procedure TMapCoreBase.GetMapClipAreaCoords(index : integer;var ca : MapClipAreaRec);
begin
if Map[index].Props.ClipArea.status = 1 then
begin
ca:=Map[index].Props.ClipArea;
end
else //no select region so we return the entire map area
begin
ca.x:=0;
ca.y:=0;
ca.x2:=Map[index].Props.Width-1;
ca.y2:=Map[index].Props.Height-1;
end;
end;
procedure TMapCoreBase.SetMapClipAreaCoords(index : integer;var ca : MapClipAreaRec);
var
temp : integer;
begin
if ca.x > ca.x2 then
begin
temp:=ca.x;
ca.x:=ca.x2;
ca.x2:=temp;
end;
if ca.y > ca.y2 then
begin
temp:=ca.y;
ca.y:=ca.y2;
ca.y2:=temp;
end;
Map[index].Props.ClipArea:=ca;
end;
Procedure TMapCoreBase.Hflip(index,x,y,x2,y2: integer);
Var
i,j : integer;
L : integer;
C,C2 : TileRec;
A : integer;
begin
L :=(x2-x) Div 2;
A :=x2;
For i:=x to (x2-L-1) do
begin
For j:=y to y2 do
begin
GetMapTile(index,i,j,C);
GetMapTile(index,A,j,C2);
SetMapTile(index,i,j,C2);
SetMapTile(index,A,j,C);
end;
Dec(A);
end;
end;
Procedure TMapCoreBase.VFlip(index,x,y,x2,y2 : integer);
Var
i,j : integer;
L : integer;
C,C2 : TileRec;
A : integer;
begin
L :=(y2-y) Div 2;
A :=y2;
For j:=y to (y2-L-1) do
begin
For i:=x to x2 do
begin
GetMapTile(index,i,j,C);
GetMapTile(index,i,A,C2);
SetMapTile(index,i,j,C2);
SetMapTile(index,i,A,C);
end;
Dec(A);
end;
end;
Procedure TMapCoreBase.ScrollLeft(index,x,y,x2,y2 : integer);
Var
i,j : integer;
c,d : TileRec;
begin
For j:=y to y2 do
begin
GetMapTile(index,x,j,d);
For i:=x+1 to x2 do
begin
GetMapTile(index,i,j,c);
SetMapTile(index,i-1,j,c);
end;
SetMapTile(index,x2,J,d);
end;
end;
Procedure TMapCoreBase.ScrollRight(index,x,y,x2,y2 : integer);
Var
i,j : integer;
c,d : TileRec;
begin
For j:=y to y2 do
begin
GetMapTile(index,x2,j,d);
For i:=x2-1 downto x do
begin
GetMapTile(index,i,j,c);
SetMapTile(index,i+1,j,c);
end;
SetMapTile(index,x,j,d);
end;
end;
Procedure TMapCoreBase.ScrollUp(index,x,y,x2,y2 : integer);
Var
i,j : integer;
c,d : TileRec;
begin
For i:=x to x2 do
begin
GetMapTile(index,i,y,d);
For j:=y to y2-1 do
begin
GetMapTile(index,i,j+1,c);
SetMapTile(index,i,j,c);
end;
SetMapTile(index,i,y2,d);
end;
end;
Procedure TMapCoreBase.ScrollDown(index,x,y,x2,y2 : integer);
Var
i,j : integer;
c,d : TileRec;
begin
For i:=x to x2 do
begin
GetMapTile(index,i,y2,d);
For j:=y2 downto y+1 do
begin
GetMapTile(index,i,j-1,c);
SetMapTile(index,i,j,c);
end;
SetMapTile(index,i,y,d);
end;
end;
procedure TMapCoreBase.ClearMap(index, value : integer);
var
i,j : integer;
begin
For j:=0 to DefMaxMapWidth-1 do
begin
For i:=0 to DefMaxMapHeight-1 do
begin
// Map[index].Tile[i,j].ImageUID:='';
Map[index].Tile[i,j].ImageIndex:=value;
end;
end;
end;
procedure TMapCoreBase.SetMapTileSize(index, twidth,theight : integer);
var
zsize : integer;
nzwidth,nzheight : integer;
begin
Map[index].Props.TileWidth:=twidth;
Map[index].Props.TileHeight:=theight;
zsize:=GetZoomSize(index);
nzwidth:=5*zsize+twidth;
nzheight:=5*zsize+theight;
SetZoomMapTileSize(index,nzwidth,nzheight);
end;
procedure TMapCoreBase.SetZoomMapTileSize(index, twidth,theight : integer);
begin
Map[index].Props.ZoomTileWidth:=twidth;
Map[index].Props.ZoomTileHeight:=theight;
end;
//not using this function - will remove in future versions
//returns how big the tile will be when zoom is applied
function TMapCoreBase.GetZoomTileSize(ZoomSize : integer) : integer;
var
i : integer;
size : integer;
begin
size:=8;
for i:=1 to ZoomSize-1 do
begin
size:=size+size;
end;
GetZoomTileSize:=size;
end;
procedure TMapCoreBase.GetMapProps(index : integer;var props : MapPropsRec);
begin
props:=Map[index].Props;
end;
procedure TMapCoreBase.SetMapProps(index : integer; props : MapPropsRec);
begin
Map[index].Props:=props;
end;
function TMapCoreBase.GetMapWidth(index : integer) : integer;
begin
GetMapWidth:=Map[index].Props.width;
end;
function TMapCoreBase.GetMapHeight(index : integer) : integer;
begin
GetMapHeight:=Map[index].Props.height;
end;
function TMapCoreBase.GetZoomMapTileWidth(index : integer) : integer;
begin
GetZoomMapTileWidth:=Map[index].Props.ZoomTilewidth;
end;
function TMapCoreBase.GetZoomMapTileHeight(index : integer) : integer;
begin
GetZoomMapTileHeight:=Map[index].Props.ZoomTileHeight;
end;
function TMapCoreBase.GetMapPageWidth(index : integer) : integer;
begin
GetMapPageWidth:=Map[index].Props.width*Map[index].Props.TileWidth;
end;
function TMapCoreBase.GetMapPageHeight(index : integer) : integer;
begin
GetMapPageHeight:=Map[index].Props.height*Map[index].Props.TileHeight;
end;
function TMapCoreBase.GetZoomMapPageWidth(index : integer) : integer;
begin
GetZoomMapPageWidth:=Map[index].Props.width*Map[index].Props.ZoomTileWidth;
end;
function TMapCoreBase.GetZoomMapPageHeight(index : integer) : integer;
begin
GetZoomMapPageHeight:=Map[index].Props.height*Map[index].Props.ZoomTileHeight;
end;
function TMapCoreBase.GetMapTileWidth(index : integer) : integer;
begin
GetMapTileWidth:=Map[index].Props.TileWidth;
end;
function TMapCoreBase.GetMapTileHeight(index : integer) : integer;
begin
GetMapTileHeight:=Map[index].Props.TileHeight;
end;
function TMapCoreBase.GetMapTileIndex(index,x,y : integer) : integer;
begin
if (x < 0) or (x >= Map[index].Props.width) or (y < 0) or (y >= Map[index].Props.height) then
result:=-1000
else
result:=Map[index].Tile[x,y].ImageIndex;
end;
procedure TMapCoreBase.SetMapTile(index,x,y : integer; var Tile : TileRec);
begin
if (x < 0) or (x >= Map[index].Props.width) or (y < 0) or (y >= Map[index].Props.height) then exit;
Map[index].Tile[x,y]:=Tile;
// Move(Tile,Map[index].Tile[x,y],sizeof(Tile));
end;
procedure TMapCoreBase.GetMapTile(index,x,y : integer;var Tile : TileRec);
begin
if (x < 0) or (x >= Map[index].Props.width) or (y < 0) or (y >= Map[index].Props.height) then exit;
Tile:=Map[index].Tile[x,y];
// Move(Map[index].Tile[x,y],Tile,sizeof(Tile));
end;
procedure TMapCoreBase.SetCurrentMap(index : integer);
begin
CurrentMap:=index;
end;
function TMapCoreBase.GetCurrentMap : integer;
begin
GetCurrentMap:=CurrentMap;
end;
function TMapCoreBase.GetMapCount : integer;
begin
GetMapCount:=MapCount;
end;
procedure TMapCoreBase.SetMapCount(count : integer);
begin
MapCount:=count;
end;
//makes index ares available to clear and resize to place map in location
procedure TMapCoreBase.InsertMap(index : integer);
var
i : integer;
begin
if (index < 0) OR (index > (MapCount-1)) then exit;
inc(MapCount);
for i:=MapCount-1 downto index+1 do
begin
Map[i]:=Map[i-1];
end;
end;
procedure TMapCoreBase.DeleteMap(index : integer);
var
i : integer;
begin
if (index < 0) then exit;
for i:=index to MapCount-2 do
begin
Map[i]:=Map[i+1];
end;
SetMapSize(MapCount-1,0,0);
dec(MapCount);
end;
procedure TMapCoreBase.AddMap; //adds image to end of list - there must atleast one map
var
props : MapPropsRec;
ExportProps : MapExportFormatRec;
Lan,Format : integer;
begin
if (MapCount=0) or (MapCount >= MaxListSize) then exit;
inc(MapCount);
//copy properties from map 0
GetMapProps(0,props);
SetMapProps(MapCount-1,props);
SetMapSize(MapCount-1,props.width,props.height);
//copy Lan and Format settings from Map 0
GetMapExportProps(0,ExportProps);
Lan:=ExportProps.Lan;
Format:=ExportProps.MapFormat;
GetMapExportProps(MapCount-1,ExportProps);
ExportProps.Lan:=Lan;
ExportProps.MapFormat:=Format;
SetMapExportProps(MapCount-1,ExportProps);
end;
procedure TMapCoreBase.CloneMap; //clones current map
var
props : MapPropsRec;
ExportProps : MapExportFormatRec;
i,j : integer;
Tile : TileRec;
begin
if (MapCount=0) or (MapCount >= MaxListSize) then exit;
inc(MapCount);
//copy properties from current map
GetMapProps(CurrentMap,props);
SetMapProps(MapCount-1,props);
SetMapSize(MapCount-1,props.width,props.height);
//copy Lan and Format settings from current Map
GetMapExportProps(CurrentMap,ExportProps);
SetMapExportProps(MapCount-1,ExportProps);
For j:=0 to props.height-1 do
begin
For i:=0 to props.width-1 do
begin
GetMapTile(CurrentMap,i,j,Tile);
SetMapTile(MapCount-1,i,j,Tile);
end;
end;
end;
function TMapCoreBase.IsMapCustomSize(index : integer) : boolean;
var
width,height : integer;
begin
width:=GetMapWidth(index);
height:=GetMapHeight(index);
result:=NOT((width=8) or (width=16) or (width=32) or (width=64) or (width=128) or (width=256)) and
((height=8) or (height=16) or (height=32) or (height=64) or (height=128) or (height=256))
end;
begin
MapCoreBase:=TMapCoreBase.Create;
end.