author | koda |
Wed, 18 Jul 2012 15:05:56 +0100 | |
changeset 7397 | 833fc211ca2d |
parent 7287 | c0825f15272e |
child 7583 | 8a9edc7cf98f |
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 |
|
7277 | 30 |
uses uLandGraphics, uConsts, uVariables, 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 |
|
4490 | 46 |
procedure chDraw(var s: shortstring); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
47 |
var rec: PointRec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
48 |
prec: ^PointRec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
49 |
pe: PPointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
50 |
i, l: byte; |
4490 | 51 |
begin |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
52 |
i:= 1; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
53 |
l:= length(s); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
54 |
while i < l do |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
55 |
begin |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
56 |
prec:= @s[i]; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
57 |
rec:= prec^; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
58 |
rec.X:= SDLNet_Read16(@rec.X); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
59 |
rec.Y:= SDLNet_Read16(@rec.Y); |
7287 | 60 |
if rec.X < -318 then rec.X:= -318; |
61 |
if rec.X > LAND_WIDTH+318 then rec.X:= LAND_WIDTH+318; |
|
62 |
if rec.Y < -318 then rec.Y:= -318; |
|
63 |
if rec.Y > LAND_HEIGHT+318 then rec.Y:= LAND_HEIGHT+318; |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
64 |
|
7043
7c080e5ac8d0
Some work to make more units compile after conversion to c
unc0rr
parents:
6898
diff
changeset
|
65 |
new(pe); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
66 |
if pointsListLast = nil then |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
67 |
pointsListHead:= pe |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
68 |
else |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
69 |
pointsListLast^.next:= pe; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
70 |
pointsListLast:= pe; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
71 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
72 |
pe^.point:= rec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
73 |
pe^.next:= nil; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
74 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
75 |
inc(i, 5) |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
76 |
end; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
77 |
end; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
78 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
79 |
procedure Draw; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
80 |
var pe: PPointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
81 |
prevPoint: PointRec; |
6781 | 82 |
radius: LongInt; |
6873 | 83 |
color: Longword; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
84 |
begin |
4648 | 85 |
// shutup compiler |
86 |
prevPoint.X:= 0; |
|
87 |
prevPoint.Y:= 0; |
|
6781 | 88 |
radius:= 0; |
4648 | 89 |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
90 |
pe:= pointsListHead; |
4648 | 91 |
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
|
92 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
93 |
while(pe <> nil) do |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
94 |
begin |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
95 |
if (pe^.point.flags and $80 <> 0) then |
4649 | 96 |
begin |
6873 | 97 |
if (pe^.point.flags and $40 <> 0) then |
98 |
color:= 0 |
|
99 |
else |
|
100 |
color:= lfBasic; |
|
101 |
radius:= (pe^.point.flags and $3F) * 5 + 3; |
|
102 |
AddFileLog('[DRAW] Move to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+'), radius = '+inttostr(radius)); |
|
103 |
FillRoundInLand(pe^.point.X, pe^.point.Y, radius, color) |
|
4649 | 104 |
end |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
105 |
else |
4649 | 106 |
begin |
6873 | 107 |
AddFileLog('[DRAW] Line to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+'), radius = '+inttostr(radius)); |
7147 | 108 |
DrawThickLine(prevPoint.X, prevPoint.Y, pe^.point.X, pe^.point.Y, radius, color); |
109 |
FillRoundInLand(pe^.point.X, pe^.point.Y, radius, color) |
|
4649 | 110 |
end; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
111 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
112 |
prevPoint:= pe^.point; |
4648 | 113 |
pe:= pe^.next; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
114 |
end; |
4490 | 115 |
end; |
116 |
||
117 |
procedure initModule; |
|
118 |
begin |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
119 |
pointsListHead:= nil; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
120 |
pointsListLast:= nil; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
121 |
|
6898 | 122 |
RegisterVariable('draw', @chDraw, false); |
4490 | 123 |
end; |
124 |
||
5066 | 125 |
procedure freeModule; |
126 |
var pe, pp: PPointEntry; |
|
127 |
begin |
|
128 |
pe:= pointsListHead; |
|
129 |
while(pe <> nil) do |
|
130 |
begin |
|
131 |
pp:= pe; |
|
132 |
pe:= pe^.next; |
|
133 |
dispose(pp); |
|
134 |
end; |
|
135 |
end; |
|
136 |
||
4457 | 137 |
end. |