4457
|
1 |
(*
|
|
2 |
* Hedgewars, a free turn based strategy game
|
|
3 |
* Copyright (c) 2010 Andrey Korotaev <unC0Rr@gmail.com>
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation; version 2 of the License
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
17 |
*)
|
|
18 |
|
|
19 |
{$INCLUDE "options.inc"}
|
|
20 |
|
|
21 |
unit uLandPainted;
|
|
22 |
|
|
23 |
interface
|
|
24 |
|
|
25 |
procedure LoadFromFile(fileName: shortstring);
|
|
26 |
|
|
27 |
implementation
|
4458
|
28 |
uses uLandGraphics, uConsts, uUtils, SDLh;
|
4457
|
29 |
|
|
30 |
type PointRec = packed record
|
4458
|
31 |
X, Y: SmallInt;
|
4457
|
32 |
flags: byte;
|
|
33 |
end;
|
|
34 |
|
4458
|
35 |
procedure DrawLineOnLand(X1, Y1, X2, Y2: LongInt);
|
|
36 |
var eX, eY, dX, dY: LongInt;
|
|
37 |
i, sX, sY, x, y, d: LongInt;
|
|
38 |
b: boolean;
|
|
39 |
len: LongWord;
|
|
40 |
begin
|
|
41 |
len:= 0;
|
|
42 |
if (X1 = X2) and (Y1 = Y2) then
|
|
43 |
begin
|
|
44 |
exit
|
|
45 |
end;
|
|
46 |
eX:= 0;
|
|
47 |
eY:= 0;
|
|
48 |
dX:= X2 - X1;
|
|
49 |
dY:= Y2 - Y1;
|
|
50 |
|
|
51 |
if (dX > 0) then sX:= 1
|
|
52 |
else
|
|
53 |
if (dX < 0) then
|
|
54 |
begin
|
|
55 |
sX:= -1;
|
|
56 |
dX:= -dX
|
|
57 |
end else sX:= dX;
|
|
58 |
|
|
59 |
if (dY > 0) then sY:= 1
|
|
60 |
else
|
|
61 |
if (dY < 0) then
|
|
62 |
begin
|
|
63 |
sY:= -1;
|
|
64 |
dY:= -dY
|
|
65 |
end else sY:= dY;
|
|
66 |
|
|
67 |
if (dX > dY) then d:= dX
|
|
68 |
else d:= dY;
|
|
69 |
|
|
70 |
x:= X1;
|
|
71 |
y:= Y1;
|
|
72 |
|
|
73 |
for i:= 0 to d do
|
|
74 |
begin
|
|
75 |
inc(eX, dX);
|
|
76 |
inc(eY, dY);
|
|
77 |
b:= false;
|
|
78 |
if (eX > d) then
|
|
79 |
begin
|
|
80 |
dec(eX, d);
|
|
81 |
inc(x, sX);
|
|
82 |
b:= true
|
|
83 |
end;
|
|
84 |
if (eY > d) then
|
|
85 |
begin
|
|
86 |
dec(eY, d);
|
|
87 |
inc(y, sY);
|
|
88 |
b:= true
|
|
89 |
end;
|
|
90 |
if b then
|
|
91 |
begin
|
|
92 |
inc(len);
|
|
93 |
if (len mod 4) = 0 then FillRoundInLand(X, Y, 34, lfBasic)
|
|
94 |
end
|
|
95 |
end
|
|
96 |
end;
|
|
97 |
|
|
98 |
|
4457
|
99 |
procedure LoadFromFile(fileName: shortstring);
|
|
100 |
var
|
|
101 |
f: file of PointRec;
|
4458
|
102 |
rec, prevRec: PointRec;
|
4457
|
103 |
begin
|
4458
|
104 |
fileMode:= 0;
|
4457
|
105 |
|
|
106 |
assignFile(f, fileName);
|
|
107 |
reset(f);
|
|
108 |
|
|
109 |
while not eof(f) do
|
|
110 |
begin
|
|
111 |
read(f, rec);
|
4458
|
112 |
rec.X:= SDLNet_Read16(@rec.X);
|
|
113 |
rec.Y:= SDLNet_Read16(@rec.Y);
|
|
114 |
|
|
115 |
// FIXME: handle single point
|
|
116 |
if eof(f) or (rec.flags and $80 <> 0) then
|
|
117 |
else
|
|
118 |
DrawLineOnLand(prevRec.X, prevRec.Y, rec.X, rec.Y);
|
|
119 |
|
|
120 |
prevRec:= rec;
|
4457
|
121 |
end;
|
|
122 |
|
|
123 |
closeFile(f);
|
|
124 |
end;
|
|
125 |
|
|
126 |
end.
|