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);
|
4490
|
26 |
procedure initModule;
|
4457
|
27 |
|
|
28 |
implementation
|
4490
|
29 |
uses uLandGraphics, uConsts, uUtils, SDLh, uCommands;
|
4457
|
30 |
|
|
31 |
type PointRec = packed record
|
4458
|
32 |
X, Y: SmallInt;
|
4457
|
33 |
flags: byte;
|
|
34 |
end;
|
|
35 |
|
4458
|
36 |
procedure DrawLineOnLand(X1, Y1, X2, Y2: LongInt);
|
|
37 |
var eX, eY, dX, dY: LongInt;
|
|
38 |
i, sX, sY, x, y, d: LongInt;
|
|
39 |
b: boolean;
|
|
40 |
len: LongWord;
|
|
41 |
begin
|
|
42 |
len:= 0;
|
|
43 |
if (X1 = X2) and (Y1 = Y2) then
|
|
44 |
begin
|
|
45 |
exit
|
|
46 |
end;
|
|
47 |
eX:= 0;
|
|
48 |
eY:= 0;
|
|
49 |
dX:= X2 - X1;
|
|
50 |
dY:= Y2 - Y1;
|
|
51 |
|
|
52 |
if (dX > 0) then sX:= 1
|
|
53 |
else
|
|
54 |
if (dX < 0) then
|
|
55 |
begin
|
|
56 |
sX:= -1;
|
|
57 |
dX:= -dX
|
|
58 |
end else sX:= dX;
|
|
59 |
|
|
60 |
if (dY > 0) then sY:= 1
|
|
61 |
else
|
|
62 |
if (dY < 0) then
|
|
63 |
begin
|
|
64 |
sY:= -1;
|
|
65 |
dY:= -dY
|
|
66 |
end else sY:= dY;
|
|
67 |
|
|
68 |
if (dX > dY) then d:= dX
|
|
69 |
else d:= dY;
|
|
70 |
|
|
71 |
x:= X1;
|
|
72 |
y:= Y1;
|
|
73 |
|
|
74 |
for i:= 0 to d do
|
|
75 |
begin
|
|
76 |
inc(eX, dX);
|
|
77 |
inc(eY, dY);
|
|
78 |
b:= false;
|
|
79 |
if (eX > d) then
|
|
80 |
begin
|
|
81 |
dec(eX, d);
|
|
82 |
inc(x, sX);
|
|
83 |
b:= true
|
|
84 |
end;
|
|
85 |
if (eY > d) then
|
|
86 |
begin
|
|
87 |
dec(eY, d);
|
|
88 |
inc(y, sY);
|
|
89 |
b:= true
|
|
90 |
end;
|
|
91 |
if b then
|
|
92 |
begin
|
|
93 |
inc(len);
|
|
94 |
if (len mod 4) = 0 then FillRoundInLand(X, Y, 34, lfBasic)
|
|
95 |
end
|
|
96 |
end
|
|
97 |
end;
|
|
98 |
|
|
99 |
|
4457
|
100 |
procedure LoadFromFile(fileName: shortstring);
|
|
101 |
var
|
|
102 |
f: file of PointRec;
|
4458
|
103 |
rec, prevRec: PointRec;
|
4457
|
104 |
begin
|
4458
|
105 |
fileMode:= 0;
|
4457
|
106 |
|
|
107 |
assignFile(f, fileName);
|
|
108 |
reset(f);
|
|
109 |
|
|
110 |
while not eof(f) do
|
|
111 |
begin
|
|
112 |
read(f, rec);
|
4458
|
113 |
rec.X:= SDLNet_Read16(@rec.X);
|
|
114 |
rec.Y:= SDLNet_Read16(@rec.Y);
|
|
115 |
|
|
116 |
// FIXME: handle single point
|
|
117 |
if eof(f) or (rec.flags and $80 <> 0) then
|
|
118 |
else
|
|
119 |
DrawLineOnLand(prevRec.X, prevRec.Y, rec.X, rec.Y);
|
|
120 |
|
|
121 |
prevRec:= rec;
|
4457
|
122 |
end;
|
|
123 |
|
|
124 |
closeFile(f);
|
|
125 |
end;
|
|
126 |
|
4490
|
127 |
procedure chDraw(var s: shortstring);
|
|
128 |
begin
|
|
129 |
end;
|
|
130 |
|
|
131 |
procedure initModule;
|
|
132 |
begin
|
|
133 |
RegisterVariable('draw', vtCommand, @chDraw, false);
|
|
134 |
end;
|
|
135 |
|
4457
|
136 |
end.
|