author | koda |
Mon, 01 Jun 2015 14:39:25 +0200 | |
branch | 0.9.20 |
changeset 9934 | 57f9ce8b2854 |
parent 9472 | 265e5997580e |
child 9998 | 736015b847e3 |
permissions | -rw-r--r-- |
4457 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
9080 | 3 |
* Copyright (c) 2004-2013 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 |
|
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
30 |
uses uLandGraphics, uConsts, uVariables, uUtils, SDLh, uCommands, uDebug, uScript; |
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; |
7583 | 61 |
if rec.X > 4096+318 then rec.X:= 4096+318; |
7287 | 62 |
if rec.Y < -318 then rec.Y:= -318; |
7583 | 63 |
if rec.Y > 2048+318 then rec.Y:= 2048+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; |
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
91 |
while (pe <> nil) and (pe^.point.flags and $80 = 0) do |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
92 |
begin |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
93 |
ScriptCall('onSpecialPoint', pe^.point.X, pe^.point.Y, pe^.point.flags); |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
94 |
pe:= pe^.next; |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
95 |
end; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
96 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
97 |
while(pe <> nil) do |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
98 |
begin |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
99 |
if (pe^.point.flags and $80 <> 0) then |
4649 | 100 |
begin |
6873 | 101 |
if (pe^.point.flags and $40 <> 0) then |
102 |
color:= 0 |
|
103 |
else |
|
104 |
color:= lfBasic; |
|
105 |
radius:= (pe^.point.flags and $3F) * 5 + 3; |
|
106 |
AddFileLog('[DRAW] Move to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+'), radius = '+inttostr(radius)); |
|
107 |
FillRoundInLand(pe^.point.X, pe^.point.Y, radius, color) |
|
4649 | 108 |
end |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
109 |
else |
4649 | 110 |
begin |
6873 | 111 |
AddFileLog('[DRAW] Line to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+'), radius = '+inttostr(radius)); |
7147 | 112 |
DrawThickLine(prevPoint.X, prevPoint.Y, pe^.point.X, pe^.point.Y, radius, color); |
113 |
FillRoundInLand(pe^.point.X, pe^.point.Y, radius, color) |
|
4649 | 114 |
end; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
115 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
116 |
prevPoint:= pe^.point; |
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
117 |
pe:= pe^.next; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
118 |
end; |
4490 | 119 |
end; |
120 |
||
121 |
procedure initModule; |
|
122 |
begin |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
123 |
pointsListHead:= nil; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
124 |
pointsListLast:= nil; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
125 |
|
6898 | 126 |
RegisterVariable('draw', @chDraw, false); |
4490 | 127 |
end; |
128 |
||
5066 | 129 |
procedure freeModule; |
130 |
var pe, pp: PPointEntry; |
|
131 |
begin |
|
132 |
pe:= pointsListHead; |
|
133 |
while(pe <> nil) do |
|
134 |
begin |
|
135 |
pp:= pe; |
|
136 |
pe:= pe^.next; |
|
137 |
dispose(pp); |
|
138 |
end; |
|
139 |
end; |
|
140 |
||
4457 | 141 |
end. |