author | Xeli |
Sat, 28 Apr 2012 14:41:40 +0200 | |
changeset 6951 | a37e470c8694 |
parent 6898 | 344b0dbd9690 |
child 7043 | 7c080e5ac8d0 |
permissions | -rw-r--r-- |
4457 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
6700 | 3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
4457 | 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 |
||
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
25 |
procedure Draw; |
4490 | 26 |
procedure initModule; |
5066 | 27 |
procedure freeModule; |
4457 | 28 |
|
29 |
implementation |
|
4648 | 30 |
uses uLandGraphics, uConsts, uUtils, SDLh, uCommands, uDebug; |
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 |
|
6873 | 46 |
procedure DrawLineOnLand(X1, Y1, X2, Y2, radius: LongInt; color: Longword); |
4458 | 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 |
||
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
62 |
if (dX > 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
63 |
sX:= 1 |
4458 | 64 |
else |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
65 |
if (dX < 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
66 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
67 |
sX:= -1; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
68 |
dX:= -dX |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
69 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
70 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
71 |
sX:= dX; |
4458 | 72 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
73 |
if (dY > 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
74 |
sY:= 1 |
4458 | 75 |
else |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
76 |
if (dY < 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
77 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
78 |
sY:= -1; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
79 |
dY:= -dY |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
80 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
81 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
82 |
sY:= dY; |
4458 | 83 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
84 |
if (dX > dY) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
85 |
d:= dX |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
86 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
87 |
d:= dY; |
4458 | 88 |
|
89 |
x:= X1; |
|
90 |
y:= Y1; |
|
91 |
||
92 |
for i:= 0 to d do |
|
93 |
begin |
|
94 |
inc(eX, dX); |
|
95 |
inc(eY, dY); |
|
96 |
b:= false; |
|
97 |
if (eX > d) then |
|
98 |
begin |
|
99 |
dec(eX, d); |
|
100 |
inc(x, sX); |
|
101 |
b:= true |
|
102 |
end; |
|
103 |
if (eY > d) then |
|
104 |
begin |
|
105 |
dec(eY, d); |
|
106 |
inc(y, sY); |
|
107 |
b:= true |
|
108 |
end; |
|
109 |
if b then |
|
110 |
begin |
|
111 |
inc(len); |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5066
diff
changeset
|
112 |
if (len mod 4) = 0 then |
6873 | 113 |
FillRoundInLand(X, Y, radius, color) |
4458 | 114 |
end |
115 |
end |
|
116 |
end; |
|
117 |
||
4490 | 118 |
procedure chDraw(var s: shortstring); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
119 |
var rec: PointRec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
120 |
prec: ^PointRec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
121 |
pe: PPointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
122 |
i, l: byte; |
4490 | 123 |
begin |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
124 |
i:= 1; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
125 |
l:= length(s); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
126 |
while i < l do |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
127 |
begin |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
128 |
prec:= @s[i]; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
129 |
rec:= prec^; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
130 |
rec.X:= SDLNet_Read16(@rec.X); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
131 |
rec.Y:= SDLNet_Read16(@rec.Y); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
132 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
133 |
pe:= new(PPointEntry); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
134 |
if pointsListLast = nil then |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
135 |
pointsListHead:= pe |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
136 |
else |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
137 |
pointsListLast^.next:= pe; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
138 |
pointsListLast:= pe; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
139 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
140 |
pe^.point:= rec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
141 |
pe^.next:= nil; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
142 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
143 |
inc(i, 5) |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
144 |
end; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
145 |
end; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
146 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
147 |
procedure Draw; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
148 |
var pe: PPointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
149 |
prevPoint: PointRec; |
6781 | 150 |
radius: LongInt; |
6873 | 151 |
color: Longword; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
152 |
begin |
4648 | 153 |
// shutup compiler |
154 |
prevPoint.X:= 0; |
|
155 |
prevPoint.Y:= 0; |
|
6781 | 156 |
radius:= 0; |
4648 | 157 |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
158 |
pe:= pointsListHead; |
4648 | 159 |
TryDo((pe = nil) or (pe^.point.flags and $80 <> 0), 'Corrupted draw data', true); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
160 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
161 |
while(pe <> nil) do |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
162 |
begin |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
163 |
if (pe^.point.flags and $80 <> 0) then |
4649 | 164 |
begin |
6873 | 165 |
if (pe^.point.flags and $40 <> 0) then |
166 |
color:= 0 |
|
167 |
else |
|
168 |
color:= lfBasic; |
|
169 |
radius:= (pe^.point.flags and $3F) * 5 + 3; |
|
170 |
AddFileLog('[DRAW] Move to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+'), radius = '+inttostr(radius)); |
|
171 |
FillRoundInLand(pe^.point.X, pe^.point.Y, radius, color) |
|
4649 | 172 |
end |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
173 |
else |
4649 | 174 |
begin |
6873 | 175 |
AddFileLog('[DRAW] Line to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+'), radius = '+inttostr(radius)); |
176 |
DrawLineOnLand(prevPoint.X, prevPoint.Y, pe^.point.X, pe^.point.Y, radius, color); |
|
4649 | 177 |
end; |
4494
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; |
4648 | 180 |
pe:= pe^.next; |
4494
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 |
|
6898 | 189 |
RegisterVariable('draw', @chDraw, false); |
4490 | 190 |
end; |
191 |
||
5066 | 192 |
procedure freeModule; |
193 |
var pe, pp: PPointEntry; |
|
194 |
begin |
|
195 |
pe:= pointsListHead; |
|
196 |
while(pe <> nil) do |
|
197 |
begin |
|
198 |
pp:= pe; |
|
199 |
pe:= pe^.next; |
|
200 |
dispose(pp); |
|
201 |
end; |
|
202 |
end; |
|
203 |
||
4457 | 204 |
end. |