author | alfadur |
Tue, 27 Aug 2019 20:09:17 +0300 | |
changeset 15388 | d6b4586b271f |
parent 15261 | 4195d2852974 |
permissions | -rw-r--r-- |
4457 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
10015
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4457 | 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 |
|
10246
8da91cd7a32a
Inform frontend of lines which didn't change anything on the map in advanced drawn maps mode
unc0rr
parents:
10244
diff
changeset
|
30 |
uses uLandGraphics, uConsts, uVariables, uUtils, SDLh, uCommands, uScript, uIO; |
4457 | 31 |
|
32 |
type PointRec = packed record |
|
4458 | 33 |
X, Y: SmallInt; |
4457 | 34 |
flags: byte; |
35 |
end; |
|
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10108
diff
changeset
|
36 |
PPointRec = ^PointRec; |
4457 | 37 |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
38 |
type |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
39 |
PPointEntry = ^PointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
40 |
PointEntry = record |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
41 |
point: PointRec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
42 |
next: PPointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
43 |
end; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
44 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
45 |
var pointsListHead, pointsListLast: PPointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
46 |
|
4490 | 47 |
procedure chDraw(var s: shortstring); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
48 |
var rec: PointRec; |
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10108
diff
changeset
|
49 |
prec: PPointRec; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
50 |
pe: PPointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
51 |
i, l: byte; |
4490 | 52 |
begin |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
53 |
i:= 1; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
54 |
l:= length(s); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
55 |
while i < l do |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
56 |
begin |
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10108
diff
changeset
|
57 |
prec:= PPointRec(@s[i]); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
58 |
rec:= prec^; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
59 |
rec.X:= SDLNet_Read16(@rec.X); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
60 |
rec.Y:= SDLNet_Read16(@rec.Y); |
15261
4195d2852974
Drawn maps: Update uLandPainted scaling to match the new map bounds
Wuzzy <Wuzzy2@mail.ru>
parents:
15178
diff
changeset
|
61 |
|
7287 | 62 |
if rec.X < -318 then rec.X:= -318; |
7583 | 63 |
if rec.X > 4096+318 then rec.X:= 4096+318; |
7287 | 64 |
if rec.Y < -318 then rec.Y:= -318; |
7583 | 65 |
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
|
66 |
|
7043
7c080e5ac8d0
Some work to make more units compile after conversion to c
unc0rr
parents:
6898
diff
changeset
|
67 |
new(pe); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
68 |
if pointsListLast = nil then |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
69 |
pointsListHead:= pe |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
70 |
else |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
71 |
pointsListLast^.next:= pe; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
72 |
pointsListLast:= pe; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
73 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
74 |
pe^.point:= rec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
75 |
pe^.next:= nil; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
76 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
77 |
inc(i, 5) |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
78 |
end; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
79 |
end; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
80 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
81 |
procedure Draw; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
82 |
var pe: PPointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
83 |
prevPoint: PointRec; |
6781 | 84 |
radius: LongInt; |
14437 | 85 |
color, Xoffset, Yoffset: Longword; |
10246
8da91cd7a32a
Inform frontend of lines which didn't change anything on the map in advanced drawn maps mode
unc0rr
parents:
10244
diff
changeset
|
86 |
lineNumber, linePoints: Longword; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
87 |
begin |
4648 | 88 |
// shutup compiler |
89 |
prevPoint.X:= 0; |
|
90 |
prevPoint.Y:= 0; |
|
6781 | 91 |
radius:= 0; |
10246
8da91cd7a32a
Inform frontend of lines which didn't change anything on the map in advanced drawn maps mode
unc0rr
parents:
10244
diff
changeset
|
92 |
linePoints:= 0; |
15261
4195d2852974
Drawn maps: Update uLandPainted scaling to match the new map bounds
Wuzzy <Wuzzy2@mail.ru>
parents:
15178
diff
changeset
|
93 |
Xoffset:= (LAND_WIDTH-(playWidth)) div 2; |
4195d2852974
Drawn maps: Update uLandPainted scaling to match the new map bounds
Wuzzy <Wuzzy2@mail.ru>
parents:
15178
diff
changeset
|
94 |
Yoffset:= LAND_HEIGHT-(playHeight); |
4648 | 95 |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
96 |
pe:= pointsListHead; |
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
97 |
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
|
98 |
begin |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
99 |
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
|
100 |
pe:= pe^.next; |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
101 |
end; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
102 |
|
10246
8da91cd7a32a
Inform frontend of lines which didn't change anything on the map in advanced drawn maps mode
unc0rr
parents:
10244
diff
changeset
|
103 |
lineNumber:= 0; |
8da91cd7a32a
Inform frontend of lines which didn't change anything on the map in advanced drawn maps mode
unc0rr
parents:
10244
diff
changeset
|
104 |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
105 |
while(pe <> nil) do |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
106 |
begin |
15261
4195d2852974
Drawn maps: Update uLandPainted scaling to match the new map bounds
Wuzzy <Wuzzy2@mail.ru>
parents:
15178
diff
changeset
|
107 |
pe^.point.X:= LongInt(pe^.point.X) * playWidth div 4096 + Xoffset; |
4195d2852974
Drawn maps: Update uLandPainted scaling to match the new map bounds
Wuzzy <Wuzzy2@mail.ru>
parents:
15178
diff
changeset
|
108 |
pe^.point.Y:= LongInt(pe^.point.Y) * playHeight div 2048 + Yoffset; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
109 |
if (pe^.point.flags and $80 <> 0) then |
4649 | 110 |
begin |
10246
8da91cd7a32a
Inform frontend of lines which didn't change anything on the map in advanced drawn maps mode
unc0rr
parents:
10244
diff
changeset
|
111 |
if (lineNumber > 0) and (linePoints = 0) and cAdvancedMapGenMode then |
8da91cd7a32a
Inform frontend of lines which didn't change anything on the map in advanced drawn maps mode
unc0rr
parents:
10244
diff
changeset
|
112 |
SendIPC('|' + inttostr(lineNumber - 1)); |
8da91cd7a32a
Inform frontend of lines which didn't change anything on the map in advanced drawn maps mode
unc0rr
parents:
10244
diff
changeset
|
113 |
|
8da91cd7a32a
Inform frontend of lines which didn't change anything on the map in advanced drawn maps mode
unc0rr
parents:
10244
diff
changeset
|
114 |
inc(lineNumber); |
8da91cd7a32a
Inform frontend of lines which didn't change anything on the map in advanced drawn maps mode
unc0rr
parents:
10244
diff
changeset
|
115 |
|
8da91cd7a32a
Inform frontend of lines which didn't change anything on the map in advanced drawn maps mode
unc0rr
parents:
10244
diff
changeset
|
116 |
if (pe^.point.flags and $40 <> 0) then |
6873 | 117 |
color:= 0 |
118 |
else |
|
119 |
color:= lfBasic; |
|
120 |
radius:= (pe^.point.flags and $3F) * 5 + 3; |
|
15261
4195d2852974
Drawn maps: Update uLandPainted scaling to match the new map bounds
Wuzzy <Wuzzy2@mail.ru>
parents:
15178
diff
changeset
|
121 |
radius:= (radius * playWidth div 4096); |
10246
8da91cd7a32a
Inform frontend of lines which didn't change anything on the map in advanced drawn maps mode
unc0rr
parents:
10244
diff
changeset
|
122 |
linePoints:= FillRoundInLand(pe^.point.X, pe^.point.Y, radius, color); |
4649 | 123 |
end |
15261
4195d2852974
Drawn maps: Update uLandPainted scaling to match the new map bounds
Wuzzy <Wuzzy2@mail.ru>
parents:
15178
diff
changeset
|
124 |
else |
4649 | 125 |
begin |
10244 | 126 |
inc(linePoints, DrawThickLine(prevPoint.X, prevPoint.Y, pe^.point.X, pe^.point.Y, radius, color)); |
4649 | 127 |
end; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
128 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
129 |
prevPoint:= pe^.point; |
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
130 |
pe:= pe^.next; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
131 |
end; |
15162
af14c418c92f
Drawn maps: Erase land outside of land bounds
Wuzzy <Wuzzy2@mail.ru>
parents:
14437
diff
changeset
|
132 |
|
af14c418c92f
Drawn maps: Erase land outside of land bounds
Wuzzy <Wuzzy2@mail.ru>
parents:
14437
diff
changeset
|
133 |
if (topY > 0) then |
15178
490bd70dac6e
Drawn maps: Fix off-by-one errors in land erasing code
Wuzzy <Wuzzy2@mail.ru>
parents:
15162
diff
changeset
|
134 |
EraseLandRectRaw(0, 0, LAND_WIDTH, topY); |
15162
af14c418c92f
Drawn maps: Erase land outside of land bounds
Wuzzy <Wuzzy2@mail.ru>
parents:
14437
diff
changeset
|
135 |
if (leftX > 0) then |
15178
490bd70dac6e
Drawn maps: Fix off-by-one errors in land erasing code
Wuzzy <Wuzzy2@mail.ru>
parents:
15162
diff
changeset
|
136 |
EraseLandRectRaw(0, topY, leftX, LAND_HEIGHT - topY); |
15162
af14c418c92f
Drawn maps: Erase land outside of land bounds
Wuzzy <Wuzzy2@mail.ru>
parents:
14437
diff
changeset
|
137 |
if (rightX < (LAND_WIDTH - 1)) then |
af14c418c92f
Drawn maps: Erase land outside of land bounds
Wuzzy <Wuzzy2@mail.ru>
parents:
14437
diff
changeset
|
138 |
EraseLandRectRaw(rightX + 1, topY, LAND_WIDTH - (rightX + 1), LAND_HEIGHT - topY); |
4490 | 139 |
end; |
140 |
||
141 |
procedure initModule; |
|
142 |
begin |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
143 |
pointsListHead:= nil; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
144 |
pointsListLast:= nil; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
145 |
|
6898 | 146 |
RegisterVariable('draw', @chDraw, false); |
4490 | 147 |
end; |
148 |
||
5066 | 149 |
procedure freeModule; |
150 |
var pe, pp: PPointEntry; |
|
151 |
begin |
|
152 |
pe:= pointsListHead; |
|
153 |
while(pe <> nil) do |
|
154 |
begin |
|
155 |
pp:= pe; |
|
156 |
pe:= pe^.next; |
|
157 |
dispose(pp); |
|
158 |
end; |
|
159 |
end; |
|
160 |
||
4457 | 161 |
end. |