10198
|
1 |
unit uLandGenTemplateBased;
|
|
2 |
interface
|
|
3 |
|
|
4 |
uses uLandTemplates;
|
|
5 |
|
|
6 |
procedure GenTemplated(var Template: TEdgeTemplate);
|
|
7 |
|
|
8 |
implementation
|
|
9 |
uses uTypes, uVariables, uConsts, uFloat, uLandOutline, uLandUtils, uRandom;
|
|
10 |
|
|
11 |
|
|
12 |
procedure SetPoints(var Template: TEdgeTemplate; var pa: TPixAr; fps: PPointArray);
|
|
13 |
var i: LongInt;
|
|
14 |
begin
|
|
15 |
with Template do
|
|
16 |
begin
|
|
17 |
pa.Count:= BasePointsCount;
|
|
18 |
for i:= 0 to pred(pa.Count) do
|
|
19 |
begin
|
|
20 |
pa.ar[i].x:= BasePoints^[i].x + LongInt(GetRandom(BasePoints^[i].w));
|
|
21 |
if pa.ar[i].x <> NTPX then
|
|
22 |
pa.ar[i].x:= pa.ar[i].x + ((LAND_WIDTH - Template.TemplateWidth) div 2);
|
|
23 |
pa.ar[i].y:= BasePoints^[i].y + LongInt(GetRandom(BasePoints^[i].h)) + LAND_HEIGHT - LongInt(Template.TemplateHeight)
|
|
24 |
end;
|
|
25 |
|
|
26 |
if canMirror then
|
|
27 |
if getrandom(2) = 0 then
|
|
28 |
begin
|
|
29 |
for i:= 0 to pred(BasePointsCount) do
|
|
30 |
if pa.ar[i].x <> NTPX then
|
|
31 |
pa.ar[i].x:= LAND_WIDTH - 1 - pa.ar[i].x;
|
|
32 |
for i:= 0 to pred(FillPointsCount) do
|
|
33 |
fps^[i].x:= LAND_WIDTH - 1 - fps^[i].x;
|
|
34 |
end;
|
|
35 |
|
|
36 |
(* Experiment in making this option more useful
|
|
37 |
if ((not isNegative) and (cTemplateFilter = 4)) or
|
|
38 |
(canFlip and (getrandom(2) = 0)) then
|
|
39 |
begin
|
|
40 |
for i:= 0 to pred(BasePointsCount) do
|
|
41 |
begin
|
|
42 |
pa.ar[i].y:= LAND_HEIGHT - 1 - pa.ar[i].y + (LAND_HEIGHT - TemplateHeight) * 2;
|
|
43 |
if pa.ar[i].y > LAND_HEIGHT - 1 then
|
|
44 |
pa.ar[i].y:= LAND_HEIGHT - 1;
|
|
45 |
end;
|
|
46 |
for i:= 0 to pred(FillPointsCount) do
|
|
47 |
begin
|
|
48 |
FillPoints^[i].y:= LAND_HEIGHT - 1 - FillPoints^[i].y + (LAND_HEIGHT - TemplateHeight) * 2;
|
|
49 |
if FillPoints^[i].y > LAND_HEIGHT - 1 then
|
|
50 |
FillPoints^[i].y:= LAND_HEIGHT - 1;
|
|
51 |
end;
|
|
52 |
end;
|
|
53 |
end
|
|
54 |
*)
|
|
55 |
// template recycling. Pull these off the floor a bit
|
|
56 |
if (not isNegative) and (cTemplateFilter = 4) then
|
|
57 |
begin
|
|
58 |
for i:= 0 to pred(BasePointsCount) do
|
|
59 |
begin
|
|
60 |
dec(pa.ar[i].y, 100);
|
|
61 |
if pa.ar[i].y < 0 then
|
|
62 |
pa.ar[i].y:= 0;
|
|
63 |
end;
|
|
64 |
for i:= 0 to pred(FillPointsCount) do
|
|
65 |
begin
|
|
66 |
dec(fps^[i].y, 100);
|
|
67 |
if fps^[i].y < 0 then
|
|
68 |
fps^[i].y:= 0;
|
|
69 |
end;
|
|
70 |
end;
|
|
71 |
|
|
72 |
if (canFlip and (getrandom(2) = 0)) then
|
|
73 |
begin
|
|
74 |
for i:= 0 to pred(BasePointsCount) do
|
|
75 |
pa.ar[i].y:= LAND_HEIGHT - 1 - pa.ar[i].y;
|
|
76 |
for i:= 0 to pred(FillPointsCount) do
|
|
77 |
fps^[i].y:= LAND_HEIGHT - 1 - fps^[i].y;
|
|
78 |
end;
|
|
79 |
end
|
|
80 |
end;
|
|
81 |
|
|
82 |
procedure GenTemplated(var Template: TEdgeTemplate);
|
|
83 |
var pa: TPixAr;
|
|
84 |
i: Longword;
|
|
85 |
y, x: Longword;
|
|
86 |
fps: TPointArray;
|
|
87 |
begin
|
|
88 |
fps:=Template.FillPoints^;
|
|
89 |
ResizeLand(Template.TemplateWidth, Template.TemplateHeight);
|
|
90 |
for y:= 0 to LAND_HEIGHT - 1 do
|
|
91 |
for x:= 0 to LAND_WIDTH - 1 do
|
|
92 |
Land[y, x]:= lfBasic;
|
|
93 |
{$HINTS OFF}
|
|
94 |
SetPoints(Template, pa, @fps);
|
|
95 |
{$HINTS ON}
|
|
96 |
|
|
97 |
for i:= 1 to Template.BezierizeCount do
|
|
98 |
begin
|
|
99 |
BezierizeEdge(pa, _0_5);
|
|
100 |
RandomizePoints(pa);
|
|
101 |
RandomizePoints(pa)
|
|
102 |
end;
|
|
103 |
for i:= 1 to Template.RandPassesCount do
|
|
104 |
RandomizePoints(pa);
|
|
105 |
BezierizeEdge(pa, _0_1);
|
|
106 |
|
|
107 |
|
|
108 |
DrawEdge(pa, 0);
|
|
109 |
|
|
110 |
with Template do
|
|
111 |
for i:= 0 to pred(FillPointsCount) do
|
|
112 |
with fps[i] do
|
|
113 |
FillLand(x, y, 0, 0);
|
|
114 |
|
|
115 |
DrawEdge(pa, lfBasic);
|
|
116 |
|
|
117 |
MaxHedgehogs:= Template.MaxHedgehogs;
|
|
118 |
hasGirders:= Template.hasGirders;
|
|
119 |
playHeight:= Template.TemplateHeight;
|
|
120 |
playWidth:= Template.TemplateWidth;
|
|
121 |
leftX:= ((LAND_WIDTH - playWidth) div 2);
|
|
122 |
rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1;
|
|
123 |
topY:= LAND_HEIGHT - playHeight;
|
|
124 |
|
|
125 |
// HACK: force to only cavern even if a cavern map is invertable if cTemplateFilter = 4 ?
|
|
126 |
if (cTemplateFilter = 4)
|
|
127 |
or (Template.canInvert and (getrandom(2) = 0))
|
|
128 |
or (not Template.canInvert and Template.isNegative) then
|
|
129 |
begin
|
|
130 |
hasBorder:= true;
|
|
131 |
for y:= 0 to LAND_HEIGHT - 1 do
|
|
132 |
for x:= 0 to LAND_WIDTH - 1 do
|
|
133 |
if (y < topY) or (x < leftX) or (x > rightX) then
|
|
134 |
Land[y, x]:= 0
|
|
135 |
else
|
|
136 |
begin
|
|
137 |
if Land[y, x] = 0 then
|
|
138 |
Land[y, x]:= lfBasic
|
|
139 |
else if Land[y, x] = lfBasic then
|
|
140 |
Land[y, x]:= 0;
|
|
141 |
end;
|
|
142 |
end;
|
|
143 |
end;
|
|
144 |
|
|
145 |
|
|
146 |
end.
|