author | unc0rr |
Wed, 15 Dec 2010 21:10:25 +0300 | |
changeset 4534 | 395278890955 |
parent 4494 | 9585435e20f7 |
child 4648 | d8e1b43482d2 |
permissions | -rw-r--r-- |
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); |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
26 |
procedure Draw; |
4490 | 27 |
procedure initModule; |
4457 | 28 |
|
29 |
implementation |
|
4490 | 30 |
uses uLandGraphics, uConsts, uUtils, SDLh, uCommands; |
4457 | 31 |
|
32 |
type PointRec = packed record |
|
4458 | 33 |
X, Y: SmallInt; |
4457 | 34 |
flags: byte; |
35 |
end; |
|
36 |
||
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
37 |
type |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
38 |
PPointEntry = ^PointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
39 |
PointEntry = record |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
40 |
point: PointRec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
41 |
next: PPointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
42 |
end; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
43 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
44 |
var pointsListHead, pointsListLast: PPointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
45 |
|
4458 | 46 |
procedure DrawLineOnLand(X1, Y1, X2, Y2: LongInt); |
47 |
var eX, eY, dX, dY: LongInt; |
|
48 |
i, sX, sY, x, y, d: LongInt; |
|
49 |
b: boolean; |
|
50 |
len: LongWord; |
|
51 |
begin |
|
52 |
len:= 0; |
|
53 |
if (X1 = X2) and (Y1 = Y2) then |
|
54 |
begin |
|
55 |
exit |
|
56 |
end; |
|
57 |
eX:= 0; |
|
58 |
eY:= 0; |
|
59 |
dX:= X2 - X1; |
|
60 |
dY:= Y2 - Y1; |
|
61 |
||
62 |
if (dX > 0) then sX:= 1 |
|
63 |
else |
|
64 |
if (dX < 0) then |
|
65 |
begin |
|
66 |
sX:= -1; |
|
67 |
dX:= -dX |
|
68 |
end else sX:= dX; |
|
69 |
||
70 |
if (dY > 0) then sY:= 1 |
|
71 |
else |
|
72 |
if (dY < 0) then |
|
73 |
begin |
|
74 |
sY:= -1; |
|
75 |
dY:= -dY |
|
76 |
end else sY:= dY; |
|
77 |
||
78 |
if (dX > dY) then d:= dX |
|
79 |
else d:= dY; |
|
80 |
||
81 |
x:= X1; |
|
82 |
y:= Y1; |
|
83 |
||
84 |
for i:= 0 to d do |
|
85 |
begin |
|
86 |
inc(eX, dX); |
|
87 |
inc(eY, dY); |
|
88 |
b:= false; |
|
89 |
if (eX > d) then |
|
90 |
begin |
|
91 |
dec(eX, d); |
|
92 |
inc(x, sX); |
|
93 |
b:= true |
|
94 |
end; |
|
95 |
if (eY > d) then |
|
96 |
begin |
|
97 |
dec(eY, d); |
|
98 |
inc(y, sY); |
|
99 |
b:= true |
|
100 |
end; |
|
101 |
if b then |
|
102 |
begin |
|
103 |
inc(len); |
|
104 |
if (len mod 4) = 0 then FillRoundInLand(X, Y, 34, lfBasic) |
|
105 |
end |
|
106 |
end |
|
107 |
end; |
|
108 |
||
109 |
||
4457 | 110 |
procedure LoadFromFile(fileName: shortstring); |
111 |
var |
|
112 |
f: file of PointRec; |
|
4458 | 113 |
rec, prevRec: PointRec; |
4457 | 114 |
begin |
4458 | 115 |
fileMode:= 0; |
4457 | 116 |
|
117 |
assignFile(f, fileName); |
|
118 |
reset(f); |
|
119 |
||
120 |
while not eof(f) do |
|
121 |
begin |
|
122 |
read(f, rec); |
|
4458 | 123 |
rec.X:= SDLNet_Read16(@rec.X); |
124 |
rec.Y:= SDLNet_Read16(@rec.Y); |
|
125 |
||
126 |
// FIXME: handle single point |
|
127 |
if eof(f) or (rec.flags and $80 <> 0) then |
|
128 |
else |
|
129 |
DrawLineOnLand(prevRec.X, prevRec.Y, rec.X, rec.Y); |
|
130 |
||
131 |
prevRec:= rec; |
|
4457 | 132 |
end; |
133 |
||
134 |
closeFile(f); |
|
135 |
end; |
|
136 |
||
4490 | 137 |
procedure chDraw(var s: shortstring); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
138 |
var rec: PointRec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
139 |
prec: ^PointRec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
140 |
pe: PPointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
141 |
i, l: byte; |
4490 | 142 |
begin |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
143 |
i:= 1; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
144 |
l:= length(s); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
145 |
while i < l do |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
146 |
begin |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
147 |
prec:= @s[i]; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
148 |
rec:= prec^; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
149 |
rec.X:= SDLNet_Read16(@rec.X); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
150 |
rec.Y:= SDLNet_Read16(@rec.Y); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
151 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
152 |
pe:= new(PPointEntry); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
153 |
if pointsListLast = nil then |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
154 |
pointsListHead:= pe |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
155 |
else |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
156 |
pointsListLast^.next:= pe; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
157 |
pointsListLast:= pe; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
158 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
159 |
pe^.point:= rec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
160 |
pe^.next:= nil; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
161 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
162 |
inc(i, 5) |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
163 |
end; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
164 |
end; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
165 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
166 |
procedure Draw; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
167 |
var pe: PPointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
168 |
prevPoint: PointRec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
169 |
begin |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
170 |
pe:= pointsListHead; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
171 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
172 |
while(pe <> nil) do |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
173 |
begin |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
174 |
if (pe^.point.flags and $80 <> 0) then |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
175 |
FillRoundInLand(pe^.point.X, pe^.point.Y, 34, lfBasic) |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
176 |
else |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
177 |
DrawLineOnLand(prevPoint.X, prevPoint.Y, pe^.point.X, pe^.point.Y); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
178 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
179 |
prevPoint:= pe^.point; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
180 |
pe:= pe^.next; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
181 |
end; |
4490 | 182 |
end; |
183 |
||
184 |
procedure initModule; |
|
185 |
begin |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
186 |
pointsListHead:= nil; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
187 |
pointsListLast:= nil; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
188 |
|
4490 | 189 |
RegisterVariable('draw', vtCommand, @chDraw, false); |
190 |
end; |
|
191 |
||
4457 | 192 |
end. |