author | nemo |
Wed, 18 Dec 2013 18:43:43 -0500 | |
changeset 9807 | a44963cc6648 |
parent 8145 | 6408c0ba4ba1 |
child 8330 | aaefa587e277 |
permissions | -rw-r--r-- |
6490 | 1 |
unit uLandOutline; |
2 |
||
3 |
interface |
|
4 |
||
5 |
uses uConsts, SDLh, uFloat; |
|
6 |
||
7 |
type TPixAr = record |
|
8 |
Count: Longword; |
|
9 |
ar: array[0..Pred(cMaxEdgePoints)] of TPoint; |
|
10 |
end; |
|
11 |
||
12 |
procedure DrawEdge(var pa: TPixAr; Color: Longword); |
|
13 |
procedure FillLand(x, y: LongInt); |
|
14 |
procedure BezierizeEdge(var pa: TPixAr; Delta: hwFloat); |
|
15 |
procedure RandomizePoints(var pa: TPixAr); |
|
16 |
||
17 |
implementation |
|
18 |
||
6491 | 19 |
uses uLandGraphics, uDebug, uVariables, uLandTemplates, uRandom, uUtils; |
6490 | 20 |
|
21 |
||
22 |
||
23 |
var Stack: record |
|
24 |
Count: Longword; |
|
25 |
points: array[0..8192] of record |
|
26 |
xl, xr, y, dir: LongInt; |
|
27 |
end |
|
28 |
end; |
|
29 |
||
8145
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
6990
diff
changeset
|
30 |
const |
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
6990
diff
changeset
|
31 |
cMaxEdgePoints = 16384; |
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
6990
diff
changeset
|
32 |
|
6490 | 33 |
procedure Push(_xl, _xr, _y, _dir: LongInt); |
34 |
begin |
|
35 |
TryDo(Stack.Count <= 8192, 'FillLand: stack overflow', true); |
|
36 |
_y:= _y + _dir; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
37 |
if (_y < 0) or (_y >= LAND_HEIGHT) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
38 |
exit; |
6490 | 39 |
with Stack.points[Stack.Count] do |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
40 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
41 |
xl:= _xl; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
42 |
xr:= _xr; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
43 |
y:= _y; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
44 |
dir:= _dir |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
45 |
end; |
6490 | 46 |
inc(Stack.Count) |
47 |
end; |
|
48 |
||
49 |
procedure Pop(var _xl, _xr, _y, _dir: LongInt); |
|
50 |
begin |
|
51 |
dec(Stack.Count); |
|
52 |
with Stack.points[Stack.Count] do |
|
53 |
begin |
|
54 |
_xl:= xl; |
|
55 |
_xr:= xr; |
|
56 |
_y:= y; |
|
57 |
_dir:= dir |
|
58 |
end |
|
59 |
end; |
|
60 |
||
61 |
procedure FillLand(x, y: LongInt); |
|
62 |
var xl, xr, dir: LongInt; |
|
63 |
begin |
|
64 |
Stack.Count:= 0; |
|
65 |
xl:= x - 1; |
|
66 |
xr:= x; |
|
67 |
Push(xl, xr, y, -1); |
|
68 |
Push(xl, xr, y, 1); |
|
69 |
dir:= 0; |
|
70 |
while Stack.Count > 0 do |
|
71 |
begin |
|
72 |
Pop(xl, xr, y, dir); |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
73 |
while (xl > 0) and (Land[y, xl] <> 0) do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
74 |
dec(xl); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
75 |
while (xr < LAND_WIDTH - 1) and (Land[y, xr] <> 0) do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
76 |
inc(xr); |
6490 | 77 |
while (xl < xr) do |
78 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
79 |
while (xl <= xr) and (Land[y, xl] = 0) do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
80 |
inc(xl); |
6490 | 81 |
x:= xl; |
82 |
while (xl <= xr) and (Land[y, xl] <> 0) do |
|
83 |
begin |
|
84 |
Land[y, xl]:= 0; |
|
85 |
inc(xl) |
|
86 |
end; |
|
87 |
if x < xl then |
|
88 |
begin |
|
89 |
Push(x, Pred(xl), y, dir); |
|
90 |
Push(x, Pred(xl), y,-dir); |
|
91 |
end; |
|
92 |
end; |
|
93 |
end; |
|
94 |
end; |
|
95 |
||
96 |
procedure DrawEdge(var pa: TPixAr; Color: Longword); |
|
97 |
var i: LongInt; |
|
98 |
begin |
|
99 |
i:= 0; |
|
100 |
with pa do |
|
101 |
while i < LongInt(Count) - 1 do |
|
102 |
if (ar[i + 1].X = NTPX) then |
|
103 |
inc(i, 2) |
|
104 |
else |
|
105 |
begin |
|
106 |
DrawLine(ar[i].x, ar[i].y, ar[i + 1].x, ar[i + 1].y, Color); |
|
107 |
inc(i) |
|
108 |
end |
|
109 |
end; |
|
110 |
||
111 |
||
112 |
procedure Vector(p1, p2, p3: TPoint; var Vx, Vy: hwFloat); |
|
113 |
var d1, d2, d: hwFloat; |
|
114 |
begin |
|
115 |
Vx:= int2hwFloat(p1.X - p3.X); |
|
116 |
Vy:= int2hwFloat(p1.Y - p3.Y); |
|
117 |
||
118 |
d:= DistanceI(p2.X - p1.X, p2.Y - p1.Y); |
|
119 |
d1:= DistanceI(p2.X - p3.X, p2.Y - p3.Y); |
|
120 |
d2:= Distance(Vx, Vy); |
|
121 |
||
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
122 |
if d1 < d then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
123 |
d:= d1; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
124 |
if d2 < d then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
125 |
d:= d2; |
6490 | 126 |
|
127 |
d:= d * _1div3; |
|
128 |
||
129 |
if d2.QWordValue = 0 then |
|
130 |
begin |
|
131 |
Vx:= _0; |
|
132 |
Vy:= _0 |
|
133 |
end |
|
134 |
else |
|
135 |
begin |
|
136 |
d2:= _1 / d2; |
|
137 |
Vx:= Vx * d2; |
|
138 |
Vy:= Vy * d2; |
|
139 |
||
140 |
Vx:= Vx * d; |
|
141 |
Vy:= Vy * d |
|
142 |
end |
|
143 |
end; |
|
144 |
||
145 |
procedure AddLoopPoints(var pa, opa: TPixAr; StartI, EndI: LongInt; Delta: hwFloat); |
|
146 |
var i, pi, ni: LongInt; |
|
147 |
NVx, NVy, PVx, PVy: hwFloat; |
|
148 |
x1, x2, y1, y2: LongInt; |
|
149 |
tsq, tcb, t, r1, r2, r3, cx1, cx2, cy1, cy2: hwFloat; |
|
150 |
X, Y: LongInt; |
|
151 |
begin |
|
152 |
pi:= EndI; |
|
153 |
i:= StartI; |
|
154 |
ni:= Succ(StartI); |
|
155 |
{$HINTS OFF} |
|
156 |
Vector(opa.ar[pi], opa.ar[i], opa.ar[ni], NVx, NVy); |
|
157 |
{$HINTS ON} |
|
158 |
repeat |
|
159 |
inc(pi); |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
160 |
if pi > EndI then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
161 |
pi:= StartI; |
6490 | 162 |
inc(i); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
163 |
if i > EndI then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
164 |
i:= StartI; |
6490 | 165 |
inc(ni); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
166 |
if ni > EndI then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
167 |
ni:= StartI; |
6490 | 168 |
PVx:= NVx; |
169 |
PVy:= NVy; |
|
170 |
Vector(opa.ar[pi], opa.ar[i], opa.ar[ni], NVx, NVy); |
|
171 |
||
172 |
x1:= opa.ar[pi].x; |
|
173 |
y1:= opa.ar[pi].y; |
|
174 |
x2:= opa.ar[i].x; |
|
175 |
y2:= opa.ar[i].y; |
|
176 |
cx1:= int2hwFloat(x1) - PVx; |
|
177 |
cy1:= int2hwFloat(y1) - PVy; |
|
178 |
cx2:= int2hwFloat(x2) + NVx; |
|
179 |
cy2:= int2hwFloat(y2) + NVy; |
|
180 |
t:= _0; |
|
181 |
while t.Round = 0 do |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
182 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
183 |
tsq:= t * t; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
184 |
tcb:= tsq * t; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
185 |
r1:= (_1 - t*3 + tsq*3 - tcb); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
186 |
r2:= ( t*3 - tsq*6 + tcb*3); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
187 |
r3:= ( tsq*3 - tcb*3); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
188 |
X:= hwRound(r1 * x1 + r2 * cx1 + r3 * cx2 + tcb * x2); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
189 |
Y:= hwRound(r1 * y1 + r2 * cy1 + r3 * cy2 + tcb * y2); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
190 |
t:= t + Delta; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
191 |
pa.ar[pa.Count].x:= X; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
192 |
pa.ar[pa.Count].y:= Y; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
193 |
inc(pa.Count); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
194 |
TryDo(pa.Count <= cMaxEdgePoints, 'Edge points overflow', true) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
195 |
end; |
6490 | 196 |
until i = StartI; |
197 |
pa.ar[pa.Count].x:= opa.ar[StartI].X; |
|
198 |
pa.ar[pa.Count].y:= opa.ar[StartI].Y; |
|
199 |
inc(pa.Count) |
|
200 |
end; |
|
201 |
||
202 |
procedure BezierizeEdge(var pa: TPixAr; Delta: hwFloat); |
|
203 |
var i, StartLoop: LongInt; |
|
204 |
opa: TPixAr; |
|
205 |
begin |
|
206 |
opa:= pa; |
|
207 |
pa.Count:= 0; |
|
208 |
i:= 0; |
|
209 |
StartLoop:= 0; |
|
210 |
while i < LongInt(opa.Count) do |
|
211 |
if (opa.ar[i + 1].X = NTPX) then |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
212 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
213 |
AddLoopPoints(pa, opa, StartLoop, i, Delta); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
214 |
inc(i, 2); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
215 |
StartLoop:= i; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
216 |
pa.ar[pa.Count].X:= NTPX; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
217 |
pa.ar[pa.Count].Y:= 0; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
218 |
inc(pa.Count); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
219 |
end else inc(i) |
6490 | 220 |
end; |
221 |
||
222 |
||
223 |
function CheckIntersect(V1, V2, V3, V4: TPoint): boolean; |
|
224 |
var c1, c2, dm: LongInt; |
|
225 |
begin |
|
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
226 |
CheckIntersect:= false; |
6490 | 227 |
dm:= (V4.y - V3.y) * (V2.x - V1.x) - (V4.x - V3.x) * (V2.y - V1.y); |
228 |
c1:= (V4.x - V3.x) * (V1.y - V3.y) - (V4.y - V3.y) * (V1.x - V3.x); |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
229 |
if dm = 0 then |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
230 |
exit; |
6490 | 231 |
|
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
232 |
CheckIntersect:= true; |
6490 | 233 |
c2:= (V2.x - V3.x) * (V1.y - V3.y) - (V2.y - V3.y) * (V1.x - V3.x); |
234 |
if dm > 0 then |
|
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
235 |
begin |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
236 |
if (c1 < 0) or (c1 > dm) then |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
237 |
CheckIntersect:= false |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
238 |
else if (c2 < 0) or (c2 > dm) then |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
239 |
CheckIntersect:= false; |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
240 |
end |
6490 | 241 |
else |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
242 |
begin |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
243 |
if (c1 > 0) or (c1 < dm) then |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
244 |
CheckIntersect:= false |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
245 |
else if (c2 > 0) or (c2 < dm) then |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
246 |
CheckIntersect:= false; |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
247 |
end; |
6490 | 248 |
|
249 |
//AddFileLog('1 (' + inttostr(V1.x) + ',' + inttostr(V1.y) + ')x(' + inttostr(V2.x) + ',' + inttostr(V2.y) + ')'); |
|
250 |
//AddFileLog('2 (' + inttostr(V3.x) + ',' + inttostr(V3.y) + ')x(' + inttostr(V4.x) + ',' + inttostr(V4.y) + ')'); |
|
251 |
end; |
|
252 |
||
253 |
||
254 |
function CheckSelfIntersect(var pa: TPixAr; ind: Longword): boolean; |
|
255 |
var i: Longword; |
|
256 |
begin |
|
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
257 |
CheckSelfIntersect:= false; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
258 |
if (ind <= 0) or (ind >= Pred(pa.Count)) then |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
259 |
exit; |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
260 |
|
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
261 |
CheckSelfIntersect:= true; |
6490 | 262 |
for i:= 1 to pa.Count - 3 do |
263 |
if (i <= ind - 1) or (i >= ind + 2) then |
|
264 |
begin |
|
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
265 |
if (i <> ind - 1) and CheckIntersect(pa.ar[ind], pa.ar[ind - 1], pa.ar[i], pa.ar[i - 1]) then |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
266 |
exit; |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
267 |
if (i <> ind + 2) and CheckIntersect(pa.ar[ind], pa.ar[ind + 1], pa.ar[i], pa.ar[i - 1]) then |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6580
diff
changeset
|
268 |
exit; |
6490 | 269 |
end; |
270 |
CheckSelfIntersect:= false |
|
271 |
end; |
|
272 |
||
273 |
procedure RandomizePoints(var pa: TPixAr); |
|
274 |
const cEdge = 55; |
|
275 |
cMinDist = 8; |
|
276 |
var radz: array[0..Pred(cMaxEdgePoints)] of LongInt; |
|
277 |
i, k, dist, px, py: LongInt; |
|
278 |
begin |
|
279 |
for i:= 0 to Pred(pa.Count) do |
|
280 |
begin |
|
281 |
radz[i]:= 0; |
|
282 |
with pa.ar[i] do |
|
283 |
if x <> NTPX then |
|
284 |
begin |
|
285 |
radz[i]:= Min(Max(x - cEdge, 0), Max(LAND_WIDTH - cEdge - x, 0)); |
|
286 |
radz[i]:= Min(radz[i], Min(Max(y - cEdge, 0), Max(LAND_HEIGHT - cEdge - y, 0))); |
|
287 |
if radz[i] > 0 then |
|
288 |
for k:= 0 to Pred(i) do |
|
289 |
begin |
|
290 |
dist:= Max(abs(x - pa.ar[k].x), abs(y - pa.ar[k].y)); |
|
291 |
radz[k]:= Max(0, Min((dist - cMinDist) div 2, radz[k])); |
|
292 |
radz[i]:= Max(0, Min(dist - radz[k] - cMinDist, radz[i])) |
|
293 |
end |
|
294 |
end; |
|
295 |
end; |
|
296 |
||
297 |
for i:= 0 to Pred(pa.Count) do |
|
298 |
with pa.ar[i] do |
|
299 |
if ((x and LAND_WIDTH_MASK) = 0) and ((y and LAND_HEIGHT_MASK) = 0) then |
|
300 |
begin |
|
301 |
px:= x; |
|
302 |
py:= y; |
|
303 |
x:= x + LongInt(GetRandom(7) - 3) * (radz[i] * 5 div 7) div 3; |
|
304 |
y:= y + LongInt(GetRandom(7) - 3) * (radz[i] * 5 div 7) div 3; |
|
305 |
if CheckSelfIntersect(pa, i) then |
|
306 |
begin |
|
307 |
x:= px; |
|
308 |
y:= py |
|
309 |
end; |
|
310 |
end |
|
311 |
end; |
|
312 |
||
313 |
||
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
314 |
end. |