author | matthijs |
Wed, 22 Mar 2006 22:26:16 +0000 | |
branch | 0.4.5 |
changeset 9958 | bed516c67d61 |
parent 9943 | bedd1ceaa101 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1878
diff
changeset
|
4 |
#include "openttd.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
473
diff
changeset
|
5 |
#include "table/strings.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2154
diff
changeset
|
6 |
#include "functions.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
507
diff
changeset
|
7 |
#include "map.h" |
2154
63a6b880b4c0
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2153
diff
changeset
|
8 |
#include "player.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1202
diff
changeset
|
9 |
#include "tile.h" |
0 | 10 |
#include "viewport.h" |
11 |
#include "command.h" |
|
2153
91e89aa8c299
(svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents:
2150
diff
changeset
|
12 |
#include "variables.h" |
2517
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
13 |
#include "table/sprites.h" |
0 | 14 |
|
15 |
typedef struct TerraformerHeightMod { |
|
16 |
TileIndex tile; |
|
17 |
byte height; |
|
18 |
} TerraformerHeightMod; |
|
19 |
||
20 |
typedef struct TerraformerState { |
|
21 |
int height[4]; |
|
22 |
uint32 flags; |
|
23 |
||
24 |
int direction; |
|
25 |
int modheight_count; |
|
26 |
int tile_table_count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
27 |
|
0 | 28 |
int32 cost; |
29 |
||
30 |
TileIndex *tile_table; |
|
31 |
TerraformerHeightMod *modheight; |
|
32 |
||
33 |
} TerraformerState; |
|
34 |
||
35 |
static int TerraformAllowTileProcess(TerraformerState *ts, TileIndex tile) |
|
36 |
{ |
|
37 |
TileIndex *t; |
|
38 |
int count; |
|
39 |
||
2639 | 40 |
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return -1; |
0 | 41 |
|
42 |
t = ts->tile_table; |
|
2639 | 43 |
for (count = ts->tile_table_count; count != 0; count--, t++) { |
44 |
if (*t == tile) return 0; |
|
0 | 45 |
} |
46 |
||
47 |
return 1; |
|
48 |
} |
|
49 |
||
50 |
static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile) |
|
51 |
{ |
|
52 |
TerraformerHeightMod *mod = ts->modheight; |
|
53 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
54 |
|
2639 | 55 |
for (count = ts->modheight_count; count != 0; count--, mod++) { |
56 |
if (mod->tile == tile) return mod->height; |
|
0 | 57 |
} |
58 |
||
1044
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
59 |
return TileHeight(tile); |
0 | 60 |
} |
61 |
||
62 |
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile) |
|
63 |
{ |
|
64 |
int count; |
|
65 |
TileIndex *t; |
|
66 |
||
67 |
count = ts->tile_table_count; |
|
68 |
||
2639 | 69 |
if (count >= 625) return; |
0 | 70 |
|
71 |
for(t = ts->tile_table; count != 0; count--,t++) { |
|
2639 | 72 |
if (*t == tile) return; |
0 | 73 |
} |
74 |
||
75 |
ts->tile_table[ts->tile_table_count++] = tile; |
|
76 |
} |
|
77 |
||
78 |
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile) |
|
79 |
{ |
|
1981 | 80 |
TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1)); |
81 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1)); |
|
82 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0)); |
|
0 | 83 |
TerraformAddDirtyTile(ts, tile); |
84 |
} |
|
85 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
86 |
static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode) |
0 | 87 |
{ |
88 |
int r; |
|
89 |
||
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
90 |
assert(tile < MapSize()); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
91 |
|
0 | 92 |
if ((r=TerraformAllowTileProcess(ts, tile)) <= 0) |
93 |
return r; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
94 |
|
9942
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
95 |
if (!IsTileType(tile, MP_RAILWAY)) { |
2686
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
96 |
int32 ret = DoCommandByTile(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 97 |
|
2686
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
98 |
if (CmdFailed(ret)) { |
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
99 |
_terraform_err_tile = tile; |
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
100 |
return -1; |
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
101 |
} |
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
102 |
|
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
103 |
ts->cost += ret; |
0 | 104 |
} |
105 |
||
2639 | 106 |
if (ts->tile_table_count >= 625) return -1; |
0 | 107 |
ts->tile_table[ts->tile_table_count++] = tile; |
108 |
||
109 |
return 0; |
|
110 |
} |
|
111 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
112 |
static bool TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height) |
0 | 113 |
{ |
114 |
int nh; |
|
115 |
TerraformerHeightMod *mod; |
|
116 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
117 |
|
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
118 |
assert(tile < MapSize()); |
0 | 119 |
|
120 |
if (height < 0) { |
|
121 |
_error_message = STR_1003_ALREADY_AT_SEA_LEVEL; |
|
122 |
return false; |
|
123 |
} |
|
124 |
||
125 |
_error_message = STR_1004_TOO_HIGH; |
|
126 |
||
2639 | 127 |
if (height > 15) return false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
128 |
|
0 | 129 |
nh = TerraformGetHeightOfTile(ts, tile); |
2639 | 130 |
if (nh < 0 || height == nh) return false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
131 |
|
1981 | 132 |
if (TerraformProc(ts, tile, 0) < 0) return false; |
133 |
if (TerraformProc(ts, tile + TileDiffXY( 0, -1), 1) < 0) return false; |
|
134 |
if (TerraformProc(ts, tile + TileDiffXY(-1, -1), 2) < 0) return false; |
|
135 |
if (TerraformProc(ts, tile + TileDiffXY(-1, 0), 3) < 0) return false; |
|
0 | 136 |
|
137 |
mod = ts->modheight; |
|
138 |
count = ts->modheight_count; |
|
139 |
||
2639 | 140 |
for (;;) { |
0 | 141 |
if (count == 0) { |
142 |
if (ts->modheight_count >= 576) |
|
143 |
return false; |
|
144 |
ts->modheight_count++; |
|
145 |
break; |
|
146 |
} |
|
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
147 |
if (mod->tile == tile) break; |
0 | 148 |
mod++; |
149 |
count--; |
|
150 |
} |
|
151 |
||
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
152 |
mod->tile = tile; |
0 | 153 |
mod->height = (byte)height; |
154 |
||
155 |
ts->cost += _price.terraform; |
|
156 |
||
157 |
{ |
|
158 |
int direction = ts->direction, r; |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
159 |
const TileIndexDiffC *ttm; |
0 | 160 |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
161 |
static const TileIndexDiffC _terraform_tilepos[] = { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
162 |
{ 1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
163 |
{-2, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
164 |
{ 1, 1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
165 |
{ 0, -2} |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
166 |
}; |
0 | 167 |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
168 |
for(ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
169 |
tile += ToTileIndexDiff(*ttm); |
0 | 170 |
|
171 |
r = TerraformGetHeightOfTile(ts, tile); |
|
172 |
if (r != height && r-direction != height && r+direction != height) { |
|
173 |
if (!TerraformTileHeight(ts, tile, r+direction)) |
|
174 |
return false; |
|
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
||
179 |
return true; |
|
180 |
} |
|
181 |
||
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
182 |
/** Terraform land |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
183 |
* @param x,y coordinates to terraform |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
184 |
* @param p1 corners to terraform. |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
185 |
* @param p2 direction; eg up or down |
0 | 186 |
*/ |
187 |
int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
188 |
{ |
|
189 |
TerraformerState ts; |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
190 |
TileIndex tile; |
0 | 191 |
int direction; |
192 |
||
193 |
TerraformerHeightMod modheight_data[576]; |
|
194 |
TileIndex tile_table_data[625]; |
|
195 |
||
196 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
197 |
||
198 |
_error_message = INVALID_STRING_ID; |
|
199 |
_terraform_err_tile = 0; |
|
200 |
||
201 |
ts.direction = direction = p2 ? 1 : -1; |
|
202 |
ts.flags = flags; |
|
203 |
ts.modheight_count = ts.tile_table_count = 0; |
|
204 |
ts.cost = 0; |
|
205 |
ts.modheight = modheight_data; |
|
206 |
ts.tile_table = tile_table_data; |
|
207 |
||
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
208 |
tile = TileVirtXY(x, y); |
0 | 209 |
|
1878
622765748231
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1796
diff
changeset
|
210 |
/* Make an extra check for map-bounds cause we add tiles to the originating tile */ |
2934
3b7eef9871f8
(svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents:
2705
diff
changeset
|
211 |
if (tile + TileDiffXY(1, 1) >= MapSize()) return CMD_ERROR; |
1878
622765748231
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1796
diff
changeset
|
212 |
|
0 | 213 |
if (p1 & 1) { |
1981 | 214 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 0), |
215 |
TileHeight(tile + TileDiffXY(1, 0)) + direction)) |
|
0 | 216 |
return CMD_ERROR; |
217 |
} |
|
218 |
||
219 |
if (p1 & 2) { |
|
1981 | 220 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 1), |
221 |
TileHeight(tile + TileDiffXY(1, 1)) + direction)) |
|
0 | 222 |
return CMD_ERROR; |
223 |
} |
|
224 |
||
225 |
if (p1 & 4) { |
|
1981 | 226 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 1), |
227 |
TileHeight(tile + TileDiffXY(0, 1)) + direction)) |
|
0 | 228 |
return CMD_ERROR; |
229 |
} |
|
230 |
||
231 |
if (p1 & 8) { |
|
1981 | 232 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 0), |
233 |
TileHeight(tile + TileDiffXY(0, 0)) + direction)) |
|
0 | 234 |
return CMD_ERROR; |
235 |
} |
|
236 |
||
9942
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
237 |
{ /* Check if tunnel or track would take damage */ |
0 | 238 |
int count; |
239 |
TileIndex *ti = ts.tile_table; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
240 |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
241 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
9942
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
242 |
uint a, b, c, d, r, min; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
243 |
TileIndex tile = *ti; |
0 | 244 |
|
9942
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
245 |
_terraform_err_tile = tile; |
0 | 246 |
|
9942
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
247 |
a = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); |
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
248 |
b = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); |
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
249 |
c = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); |
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
250 |
d = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); |
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
251 |
|
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
252 |
r = GetTileh(a, b, c, d, &min); |
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
253 |
|
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
254 |
if (IsTileType(tile, MP_RAILWAY)) { |
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
255 |
if (IsSteepTileh(r)) return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
256 |
|
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
257 |
if (IsPlainRailTile(tile)) { |
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
258 |
extern const TrackBits _valid_tileh_slopes[2][15]; |
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
259 |
if (GetTrackBits(tile) & ~_valid_tileh_slopes[0][r]) return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
260 |
} else return_cmd_error(STR_5800_OBJECT_IN_THE_WAY); |
2639 | 261 |
} |
9942
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
262 |
|
9943
bedd1ceaa101
(svn r4013) -Fix last commit. CheckTunnelInWay works differently from IsTunnelInWay :S
celestar
parents:
9942
diff
changeset
|
263 |
if (direction == -1 && !CheckTunnelInWay(tile, min)) return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); |
9942
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
264 |
|
56446313309e
(svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
2934
diff
changeset
|
265 |
_terraform_err_tile = 0; |
0 | 266 |
} |
267 |
} |
|
268 |
||
269 |
if (flags & DC_EXEC) { |
|
270 |
/* Clear the landscape at the tiles */ |
|
271 |
{ |
|
272 |
int count; |
|
273 |
TileIndex *ti = ts.tile_table; |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
274 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 275 |
DoCommandByTile(*ti, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
276 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
277 |
} |
0 | 278 |
|
279 |
/* change the height */ |
|
280 |
{ |
|
281 |
int count; |
|
282 |
TerraformerHeightMod *mod; |
|
283 |
||
284 |
mod = ts.modheight; |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
285 |
for (count = ts.modheight_count; count != 0; count--, mod++) { |
1979
f4462d4e8e62
(svn r2485) Missed two uint -> TileIndex, thanks _Luca_
tron
parents:
1977
diff
changeset
|
286 |
TileIndex til = mod->tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
287 |
|
1059
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
288 |
SetTileHeight(til, mod->height); |
0 | 289 |
TerraformAddDirtyTileAround(&ts, til); |
290 |
} |
|
291 |
} |
|
292 |
||
293 |
/* finally mark the dirty tiles dirty */ |
|
294 |
{ |
|
295 |
int count; |
|
296 |
TileIndex *ti = ts.tile_table; |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
297 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 298 |
MarkTileDirtyByTile(*ti); |
299 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
300 |
} |
0 | 301 |
} |
302 |
return ts.cost; |
|
303 |
} |
|
304 |
||
305 |
||
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
306 |
/** Levels a selected (rectangle) area of land |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
307 |
* @param x,y end tile of area-drag |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
308 |
* @param p1 start tile of area drag |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
309 |
* @param p2 unused |
0 | 310 |
*/ |
311 |
int32 CmdLevelLand(int ex, int ey, uint32 flags, uint32 p1, uint32 p2) |
|
312 |
{ |
|
313 |
int size_x, size_y; |
|
314 |
int sx, sy; |
|
315 |
uint h, curh; |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
316 |
TileIndex tile; |
0 | 317 |
int32 ret, cost, money; |
318 |
||
2934
3b7eef9871f8
(svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents:
2705
diff
changeset
|
319 |
if (p1 >= MapSize()) return CMD_ERROR; |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
320 |
|
889
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
863
diff
changeset
|
321 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
863
diff
changeset
|
322 |
|
0 | 323 |
// remember level height |
1044
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
324 |
h = TileHeight(p1); |
0 | 325 |
|
326 |
ex >>= 4; ey >>= 4; |
|
327 |
||
328 |
// make sure sx,sy are smaller than ex,ey |
|
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
329 |
sx = TileX(p1); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
330 |
sy = TileY(p1); |
0 | 331 |
if (ex < sx) intswap(ex, sx); |
332 |
if (ey < sy) intswap(ey, sy); |
|
1981 | 333 |
tile = TileXY(sx, sy); |
0 | 334 |
|
335 |
size_x = ex-sx+1; |
|
336 |
size_y = ey-sy+1; |
|
337 |
||
338 |
money = GetAvailableMoneyForCommand(); |
|
339 |
cost = 0; |
|
340 |
||
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
341 |
BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) { |
1044
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
342 |
curh = TileHeight(tile2); |
0 | 343 |
while (curh != h) { |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
344 |
ret = DoCommandByTile(tile2, 8, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND); |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
345 |
if (CmdFailed(ret)) break; |
0 | 346 |
cost += ret; |
347 |
||
348 |
if (flags & DC_EXEC) { |
|
349 |
if ((money -= ret) < 0) { |
|
350 |
_additional_cash_required = ret; |
|
351 |
return cost - ret; |
|
352 |
} |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
353 |
DoCommandByTile(tile2, 8, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND); |
0 | 354 |
} |
355 |
||
356 |
curh += (curh > h) ? -1 : 1; |
|
357 |
} |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
358 |
} END_TILE_LOOP(tile2, size_x, size_y, tile) |
0 | 359 |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
360 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 361 |
} |
362 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
363 |
/** Purchase a land area. Actually you only purchase one tile, so |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
364 |
* the name is a bit confusing ;p |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
365 |
* @param x,y the tile the player is purchasing |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
366 |
* @param p1 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
367 |
* @param p2 unused |
0 | 368 |
*/ |
369 |
int32 CmdPurchaseLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
370 |
{ |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
371 |
TileIndex tile; |
0 | 372 |
int32 cost; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
373 |
|
0 | 374 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
375 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
376 |
tile = TileVirtXY(x, y); |
0 | 377 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
378 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 379 |
|
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
380 |
if (IsTileType(tile, MP_UNMOVABLE) && _m[tile].m5 == 3 && |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
381 |
IsTileOwner(tile, _current_player)) |
0 | 382 |
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT); |
383 |
||
384 |
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
385 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 386 |
|
387 |
if (flags & DC_EXEC) { |
|
388 |
ModifyTile(tile, |
|
389 |
MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
390 |
3 /* map5 */ |
|
391 |
); |
|
392 |
} |
|
393 |
||
394 |
return cost + _price.purchase_land * 10; |
|
395 |
} |
|
396 |
||
397 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
398 |
static int32 ClearTile_Clear(TileIndex tile, byte flags) |
1095 | 399 |
{ |
2220 | 400 |
static const int32 null = 0; |
401 |
static const int32* clear_price_table[] = { |
|
402 |
&null, |
|
403 |
&_price.clear_1, |
|
404 |
&_price.clear_1, |
|
405 |
&_price.clear_1, |
|
406 |
&_price.purchase_land, |
|
407 |
&_price.purchase_land, |
|
408 |
&_price.purchase_land, |
|
409 |
&_price.purchase_land, |
|
410 |
&_price.clear_2, |
|
411 |
&_price.clear_2, |
|
412 |
&_price.clear_2, |
|
413 |
&_price.clear_2, |
|
414 |
&_price.clear_3, |
|
415 |
&_price.clear_3, |
|
416 |
&_price.clear_3, |
|
417 |
&_price.clear_3, |
|
418 |
&_price.purchase_land, |
|
419 |
&_price.purchase_land, |
|
420 |
&_price.purchase_land, |
|
421 |
&_price.purchase_land, |
|
422 |
&_price.purchase_land, |
|
423 |
&_price.purchase_land, |
|
424 |
&_price.purchase_land, |
|
425 |
&_price.purchase_land, |
|
426 |
&_price.clear_2, |
|
427 |
&_price.clear_2, |
|
428 |
&_price.clear_2, |
|
429 |
&_price.clear_2, |
|
0 | 430 |
}; |
2220 | 431 |
const int32 *price = clear_price_table[GB(_m[tile].m5, 0, 5)]; |
0 | 432 |
|
2220 | 433 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 434 |
|
435 |
return *price; |
|
436 |
} |
|
437 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
438 |
/** Sell a land area. Actually you only sell one tile, so |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
439 |
* the name is a bit confusing ;p |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
440 |
* @param x,y the tile the player is selling |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
441 |
* @param p1 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
442 |
* @param p2 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
443 |
*/ |
0 | 444 |
int32 CmdSellLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
445 |
{ |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
446 |
TileIndex tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
447 |
|
0 | 448 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
449 |
||
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
450 |
tile = TileVirtXY(x, y); |
0 | 451 |
|
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
452 |
if (!IsTileType(tile, MP_UNMOVABLE) || _m[tile].m5 != 3) return CMD_ERROR; |
1878
622765748231
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1796
diff
changeset
|
453 |
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR; |
622765748231
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1796
diff
changeset
|
454 |
|
0 | 455 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
456 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 457 |
|
458 |
if (flags & DC_EXEC) |
|
459 |
DoClearSquare(tile); |
|
460 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
461 |
return - _price.purchase_land * 2; |
0 | 462 |
} |
463 |
||
464 |
||
465 |
#include "table/clear_land.h" |
|
466 |
||
467 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
468 |
void DrawClearLandTile(const TileInfo *ti, byte set) |
0 | 469 |
{ |
2517
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
470 |
DrawGroundSprite(SPR_FLAT_BARE_LAND + _tileh_to_sprite[ti->tileh] + set * 19); |
0 | 471 |
} |
472 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
473 |
void DrawHillyLandTile(const TileInfo *ti) |
0 | 474 |
{ |
475 |
if (ti->tileh != 0) { |
|
2517
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
476 |
DrawGroundSprite(SPR_FLAT_ROUGH_LAND + _tileh_to_sprite[ti->tileh]); |
0 | 477 |
} else { |
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2051
diff
changeset
|
478 |
DrawGroundSprite(_landscape_clear_sprites[GB(ti->x ^ ti->y, 4, 3)]); |
0 | 479 |
} |
480 |
} |
|
481 |
||
2220 | 482 |
void DrawClearLandFence(const TileInfo *ti) |
0 | 483 |
{ |
2220 | 484 |
byte m4 = _m[ti->tile].m4; |
0 | 485 |
byte z = ti->z; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
486 |
|
0 | 487 |
if (ti->tileh & 2) { |
488 |
z += 8; |
|
2639 | 489 |
if (ti->tileh == 0x17) z += 8; |
0 | 490 |
} |
491 |
||
2220 | 492 |
if (GB(m4, 5, 3) != 0) { |
493 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GB(m4, 5, 3) - 1] + _fence_mod_by_tileh[ti->tileh], ti->x, ti->y, z); |
|
0 | 494 |
} |
495 |
||
2220 | 496 |
if (GB(m4, 2, 3) != 0) { |
497 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GB(m4, 2, 3) - 1] + _fence_mod_by_tileh_2[ti->tileh], ti->x, ti->y, z); |
|
0 | 498 |
} |
499 |
} |
|
500 |
||
501 |
static void DrawTile_Clear(TileInfo *ti) |
|
502 |
{ |
|
2220 | 503 |
switch (GB(ti->map5, 2, 3)) { |
0 | 504 |
case 0: |
2220 | 505 |
DrawClearLandTile(ti, GB(ti->map5, 0, 2)); |
0 | 506 |
break; |
507 |
||
508 |
case 1: |
|
509 |
DrawHillyLandTile(ti); |
|
510 |
break; |
|
511 |
||
512 |
case 2: |
|
2517
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
513 |
DrawGroundSprite(SPR_FLAT_ROCKY_LAND_1 + _tileh_to_sprite[ti->tileh]); |
0 | 514 |
break; |
515 |
||
516 |
case 3: |
|
2220 | 517 |
DrawGroundSprite(_clear_land_sprites_1[GB(_m[ti->tile].m3, 0, 4)] + _tileh_to_sprite[ti->tileh]); |
0 | 518 |
break; |
519 |
||
520 |
case 4: |
|
2220 | 521 |
DrawGroundSprite(_clear_land_sprites_2[GB(ti->map5, 0, 2)] + _tileh_to_sprite[ti->tileh]); |
0 | 522 |
break; |
523 |
||
524 |
case 5: |
|
2220 | 525 |
DrawGroundSprite(_clear_land_sprites_3[GB(ti->map5, 0, 2)] + _tileh_to_sprite[ti->tileh]); |
0 | 526 |
break; |
527 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
528 |
|
2220 | 529 |
DrawClearLandFence(ti); |
0 | 530 |
} |
531 |
||
2537 | 532 |
static uint GetSlopeZ_Clear(const TileInfo* ti) |
1095 | 533 |
{ |
534 |
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z; |
|
535 |
} |
|
0 | 536 |
|
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
537 |
static uint GetSlopeTileh_Clear(const TileInfo *ti) |
39 | 538 |
{ |
539 |
return ti->tileh; |
|
540 |
} |
|
541 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
542 |
static void GetAcceptedCargo_Clear(TileIndex tile, AcceptedCargo ac) |
0 | 543 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
544 |
/* unused */ |
0 | 545 |
} |
546 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
547 |
static void AnimateTile_Clear(TileIndex tile) |
0 | 548 |
{ |
549 |
/* unused */ |
|
550 |
} |
|
551 |
||
1293 | 552 |
void TileLoopClearHelper(TileIndex tile) |
0 | 553 |
{ |
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
554 |
byte self; |
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
555 |
byte neighbour; |
1293 | 556 |
TileIndex dirty = INVALID_TILE; |
0 | 557 |
|
1293 | 558 |
switch (GetTileType(tile)) { |
559 |
case MP_CLEAR: |
|
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
560 |
self = (GB(_m[tile].m5, 0, 5) == 15); |
1298 | 561 |
break; |
1293 | 562 |
|
563 |
default: |
|
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
564 |
self = 0; |
1293 | 565 |
break; |
0 | 566 |
} |
567 |
||
1293 | 568 |
switch (GetTileType(TILE_ADDXY(tile, 1, 0))) { |
569 |
case MP_CLEAR: |
|
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
570 |
neighbour = (GB(_m[TILE_ADDXY(tile, 1, 0)].m5, 0, 5) == 15); |
1293 | 571 |
break; |
572 |
||
573 |
default: |
|
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
574 |
neighbour = 0; |
1293 | 575 |
break; |
0 | 576 |
} |
577 |
||
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
578 |
if (GB(_m[tile].m4, 5, 3) == 0) { |
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
579 |
if (self != neighbour) { |
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
580 |
SB(_m[tile].m4, 5, 3, 3); |
0 | 581 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
582 |
} |
0 | 583 |
} else { |
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
584 |
if (self == 0 && neighbour == 0) { |
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
585 |
SB(_m[tile].m4, 5, 3, 0); |
0 | 586 |
dirty = tile; |
587 |
} |
|
588 |
} |
|
589 |
||
1293 | 590 |
switch (GetTileType(TILE_ADDXY(tile, 0, 1))) { |
591 |
case MP_CLEAR: |
|
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
592 |
neighbour = (GB(_m[TILE_ADDXY(tile, 0, 1)].m5, 0, 5) == 15); |
1293 | 593 |
break; |
594 |
||
595 |
default: |
|
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
596 |
neighbour = 0; |
1293 | 597 |
break; |
0 | 598 |
} |
599 |
||
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
600 |
if (GB(_m[tile].m4, 2, 3) == 0) { |
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
601 |
if (self != neighbour) { |
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
602 |
SB(_m[tile].m4, 2, 3, 3); |
0 | 603 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
604 |
} |
0 | 605 |
} else { |
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
606 |
if (self == 0 && neighbour == 0) { |
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
607 |
SB(_m[tile].m4, 2, 3, 0); |
0 | 608 |
dirty = tile; |
609 |
} |
|
610 |
} |
|
611 |
||
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
612 |
if (dirty != INVALID_TILE) MarkTileDirtyByTile(dirty); |
0 | 613 |
} |
614 |
||
615 |
||
616 |
/* convert into snowy tiles */ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
617 |
static void TileLoopClearAlps(TileIndex tile) |
0 | 618 |
{ |
619 |
int k; |
|
620 |
byte m5,tmp; |
|
621 |
||
622 |
/* distance from snow line, in steps of 8 */ |
|
623 |
k = GetTileZ(tile) - _opt.snow_line; |
|
624 |
||
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
625 |
m5 = _m[tile].m5 & 0x1C; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
626 |
tmp = _m[tile].m5 & 3; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
627 |
|
0 | 628 |
if (k < -8) { |
629 |
/* snow_m2_down */ |
|
630 |
if (m5 != 0x10) |
|
631 |
return; |
|
632 |
if (tmp == 0) |
|
633 |
m5 = 3; |
|
634 |
} else if (k == -8) { |
|
635 |
/* snow_m1 */ |
|
636 |
if (m5 != 0x10) { |
|
637 |
m5 = 0x10; |
|
638 |
} else if (tmp != 0) { |
|
639 |
m5 = (tmp - 1) + 0x10; |
|
640 |
} else |
|
641 |
return; |
|
642 |
} else if (k < 8) { |
|
643 |
/* snow_0 */ |
|
644 |
if (m5 != 0x10) { |
|
645 |
m5 = 0x10; |
|
646 |
} else if (tmp != 1) { |
|
647 |
m5 = 1; |
|
648 |
if (tmp != 0) |
|
649 |
m5 = tmp - 1; |
|
650 |
m5 += 0x10; |
|
651 |
} else |
|
652 |
return; |
|
653 |
} else if (k == 8) { |
|
654 |
/* snow_p1 */ |
|
655 |
if (m5 != 0x10) { |
|
656 |
m5 = 0x10; |
|
657 |
} else if (tmp != 2) { |
|
658 |
m5 = 2; |
|
659 |
if (tmp <= 2) |
|
660 |
m5 = tmp + 1; |
|
661 |
m5 += 0x10; |
|
662 |
} else |
|
663 |
return; |
|
664 |
} else { |
|
665 |
/* snow_p2_up */ |
|
666 |
if (m5 != 0x10) { |
|
667 |
m5 = 0x10; |
|
668 |
} else if (tmp != 3) { |
|
669 |
m5 = tmp + 1 + 0x10; |
|
670 |
} else |
|
671 |
return; |
|
672 |
} |
|
673 |
||
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
674 |
_m[tile].m5 = m5; |
0 | 675 |
MarkTileDirtyByTile(tile); |
676 |
} |
|
677 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
678 |
static void TileLoopClearDesert(TileIndex tile) |
0 | 679 |
{ |
2639 | 680 |
if ((_m[tile].m5 & 0x1C) == 0x14) return; |
0 | 681 |
|
682 |
if (GetMapExtraBits(tile) == 1) { |
|
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
683 |
_m[tile].m5 = 0x17; |
0 | 684 |
} else { |
1981 | 685 |
if (GetMapExtraBits(tile + TileDiffXY( 1, 0)) != 1 && |
686 |
GetMapExtraBits(tile + TileDiffXY(-1, 0)) != 1 && |
|
687 |
GetMapExtraBits(tile + TileDiffXY( 0, 1)) != 1 && |
|
688 |
GetMapExtraBits(tile + TileDiffXY( 0, -1)) != 1) |
|
689 |
return; |
|
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
690 |
_m[tile].m5 = 0x15; |
0 | 691 |
} |
692 |
||
693 |
MarkTileDirtyByTile(tile); |
|
694 |
} |
|
695 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
696 |
static void TileLoop_Clear(TileIndex tile) |
0 | 697 |
{ |
698 |
byte m5,m3; |
|
699 |
||
700 |
TileLoopClearHelper(tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
701 |
|
0 | 702 |
if (_opt.landscape == LT_DESERT) { |
703 |
TileLoopClearDesert(tile); |
|
704 |
} else if (_opt.landscape == LT_HILLY) { |
|
705 |
TileLoopClearAlps(tile); |
|
706 |
} |
|
707 |
||
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
708 |
m5 = _m[tile].m5; |
2639 | 709 |
if ((m5 & 0x1C) == 0x10 || (m5 & 0x1C) == 0x14) return; |
0 | 710 |
|
2639 | 711 |
if ((m5 & 0x1C) != 0xC) { |
712 |
if ((m5 & 3) == 3) return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
713 |
|
0 | 714 |
if (_game_mode != GM_EDITOR) { |
715 |
m5 += 0x20; |
|
716 |
if (m5 >= 0x20) { |
|
717 |
// Didn't overflow |
|
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
718 |
_m[tile].m5 = m5; |
0 | 719 |
return; |
720 |
} |
|
721 |
/* did overflow, so continue */ |
|
722 |
} else { |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
723 |
m5 = (GB(Random(), 0, 8) > 21) ? 2 : 6; |
0 | 724 |
} |
725 |
m5++; |
|
726 |
} else if (_game_mode != GM_EDITOR) { |
|
727 |
/* handle farm field */ |
|
728 |
m5 += 0x20; |
|
729 |
if (m5 >= 0x20) { |
|
730 |
// Didn't overflow |
|
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
731 |
_m[tile].m5 = m5; |
0 | 732 |
return; |
733 |
} |
|
734 |
/* overflowed */ |
|
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
735 |
m3 = _m[tile].m3 + 1; |
0 | 736 |
assert( (m3 & 0xF) != 0); |
737 |
if ( (m3 & 0xF) >= 9) /* NOTE: will not work properly if m3&0xF == 0xF */ |
|
738 |
m3 &= ~0xF; |
|
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
739 |
_m[tile].m3 = m3; |
0 | 740 |
} |
741 |
||
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
742 |
_m[tile].m5 = m5; |
0 | 743 |
MarkTileDirtyByTile(tile); |
744 |
} |
|
745 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
746 |
void GenerateClearTile(void) |
0 | 747 |
{ |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
748 |
uint i; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
749 |
TileIndex tile; |
0 | 750 |
|
751 |
/* add hills */ |
|
2635 | 752 |
i = ScaleByMapSize(GB(Random(), 0, 10) + 0x400); |
0 | 753 |
do { |
2051 | 754 |
tile = RandomTile(); |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
755 |
if (IsTileType(tile, MP_CLEAR)) SB(_m[tile].m5, 2, 2, 1); |
0 | 756 |
} while (--i); |
757 |
||
758 |
/* add grey squares */ |
|
2635 | 759 |
i = ScaleByMapSize(GB(Random(), 0, 7) + 0x80); |
0 | 760 |
do { |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
761 |
uint32 r = Random(); |
2051 | 762 |
tile = RandomTileSeed(r); |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
926
diff
changeset
|
763 |
if (IsTileType(tile, MP_CLEAR)) { |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
764 |
uint j = GB(r, 16, 4) + 5; |
0 | 765 |
for(;;) { |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
766 |
TileIndex tile_new; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
767 |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
768 |
SB(_m[tile].m5, 2, 2, 2); |
0 | 769 |
do { |
770 |
if (--j == 0) goto get_out; |
|
2635 | 771 |
tile_new = tile + TileOffsByDir(GB(Random(), 0, 2)); |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
926
diff
changeset
|
772 |
} while (!IsTileType(tile_new, MP_CLEAR)); |
0 | 773 |
tile = tile_new; |
774 |
} |
|
775 |
get_out:; |
|
776 |
} |
|
777 |
} while (--i); |
|
778 |
} |
|
779 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
780 |
static void ClickTile_Clear(TileIndex tile) |
0 | 781 |
{ |
782 |
/* not used */ |
|
783 |
} |
|
784 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
785 |
static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode) |
0 | 786 |
{ |
787 |
return 0; |
|
788 |
} |
|
789 |
||
2220 | 790 |
static const StringID _clear_land_str[] = { |
0 | 791 |
STR_080B_ROUGH_LAND, |
792 |
STR_080A_ROCKS, |
|
793 |
STR_080E_FIELDS, |
|
794 |
STR_080F_SNOW_COVERED_LAND, |
|
795 |
STR_0810_DESERT, |
|
796 |
0, |
|
797 |
0, |
|
798 |
STR_080C_BARE_LAND, |
|
799 |
STR_080D_GRASS, |
|
800 |
STR_080D_GRASS, |
|
801 |
STR_080D_GRASS, |
|
802 |
}; |
|
803 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
804 |
static void GetTileDesc_Clear(TileIndex tile, TileDesc *td) |
0 | 805 |
{ |
2220 | 806 |
uint i = GB(_m[tile].m5, 2, 3); |
807 |
if (i == 0) i = GB(_m[tile].m5, 0, 2) + 8; |
|
0 | 808 |
td->str = _clear_land_str[i - 1]; |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
809 |
td->owner = GetTileOwner(tile); |
0 | 810 |
} |
811 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
812 |
static void ChangeTileOwner_Clear(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 813 |
{ |
814 |
return; |
|
815 |
} |
|
816 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
817 |
void InitializeClearLand(void) |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
818 |
{ |
0 | 819 |
_opt.snow_line = _patches.snow_line_height * 8; |
820 |
} |
|
821 |
||
822 |
const TileTypeProcs _tile_type_clear_procs = { |
|
823 |
DrawTile_Clear, /* draw_tile_proc */ |
|
824 |
GetSlopeZ_Clear, /* get_slope_z_proc */ |
|
825 |
ClearTile_Clear, /* clear_tile_proc */ |
|
826 |
GetAcceptedCargo_Clear, /* get_accepted_cargo_proc */ |
|
827 |
GetTileDesc_Clear, /* get_tile_desc_proc */ |
|
828 |
GetTileTrackStatus_Clear, /* get_tile_track_status_proc */ |
|
829 |
ClickTile_Clear, /* click_tile_proc */ |
|
830 |
AnimateTile_Clear, /* animate_tile_proc */ |
|
831 |
TileLoop_Clear, /* tile_loop_clear */ |
|
832 |
ChangeTileOwner_Clear, /* change_tile_owner_clear */ |
|
833 |
NULL, /* get_produced_cargo_proc */ |
|
834 |
NULL, /* vehicle_enter_tile_proc */ |
|
835 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 836 |
GetSlopeTileh_Clear, /* get_slope_tileh_proc */ |
0 | 837 |
}; |