author | truelight |
Sat, 19 Aug 2006 10:00:30 +0000 | |
changeset 4300 | c7e43c47a2b9 |
parent 4231 | 2823b3643862 |
child 4328 | 1b3940c35724 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1878
diff
changeset
|
4 |
#include "openttd.h" |
3144
33e42feae531
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
2989
diff
changeset
|
5 |
#include "clear_map.h" |
4041
72276cd8ee2b
(svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents:
4031
diff
changeset
|
6 |
#include "rail_map.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
473
diff
changeset
|
7 |
#include "table/strings.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2154
diff
changeset
|
8 |
#include "functions.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
507
diff
changeset
|
9 |
#include "map.h" |
2154
f86c59e73a16
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2153
diff
changeset
|
10 |
#include "player.h" |
1209
2e00193652b2
(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
|
11 |
#include "tile.h" |
0 | 12 |
#include "viewport.h" |
13 |
#include "command.h" |
|
3156
f4caf4197189
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3144
diff
changeset
|
14 |
#include "tunnel_map.h" |
2153
ecfc674410b4
(svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents:
2150
diff
changeset
|
15 |
#include "variables.h" |
2517
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
16 |
#include "table/sprites.h" |
3310
a19f247b75b6
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
17 |
#include "unmovable_map.h" |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
18 |
#include "genworld.h" |
0 | 19 |
|
20 |
typedef struct TerraformerHeightMod { |
|
21 |
TileIndex tile; |
|
22 |
byte height; |
|
23 |
} TerraformerHeightMod; |
|
24 |
||
25 |
typedef struct TerraformerState { |
|
26 |
int height[4]; |
|
27 |
uint32 flags; |
|
28 |
||
29 |
int direction; |
|
30 |
int modheight_count; |
|
31 |
int tile_table_count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
32 |
|
0 | 33 |
int32 cost; |
34 |
||
35 |
TileIndex *tile_table; |
|
36 |
TerraformerHeightMod *modheight; |
|
37 |
||
38 |
} TerraformerState; |
|
39 |
||
40 |
static int TerraformAllowTileProcess(TerraformerState *ts, TileIndex tile) |
|
41 |
{ |
|
42 |
TileIndex *t; |
|
43 |
int count; |
|
44 |
||
2639 | 45 |
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return -1; |
0 | 46 |
|
47 |
t = ts->tile_table; |
|
2639 | 48 |
for (count = ts->tile_table_count; count != 0; count--, t++) { |
49 |
if (*t == tile) return 0; |
|
0 | 50 |
} |
51 |
||
52 |
return 1; |
|
53 |
} |
|
54 |
||
55 |
static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile) |
|
56 |
{ |
|
57 |
TerraformerHeightMod *mod = ts->modheight; |
|
58 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
59 |
|
2639 | 60 |
for (count = ts->modheight_count; count != 0; count--, mod++) { |
61 |
if (mod->tile == tile) return mod->height; |
|
0 | 62 |
} |
63 |
||
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
64 |
return TileHeight(tile); |
0 | 65 |
} |
66 |
||
67 |
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile) |
|
68 |
{ |
|
69 |
int count; |
|
70 |
TileIndex *t; |
|
71 |
||
72 |
count = ts->tile_table_count; |
|
73 |
||
2639 | 74 |
if (count >= 625) return; |
0 | 75 |
|
2952 | 76 |
for (t = ts->tile_table; count != 0; count--,t++) { |
2639 | 77 |
if (*t == tile) return; |
0 | 78 |
} |
79 |
||
80 |
ts->tile_table[ts->tile_table_count++] = tile; |
|
81 |
} |
|
82 |
||
83 |
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile) |
|
84 |
{ |
|
1981 | 85 |
TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1)); |
86 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1)); |
|
87 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0)); |
|
0 | 88 |
TerraformAddDirtyTile(ts, tile); |
89 |
} |
|
90 |
||
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
91 |
static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode) |
0 | 92 |
{ |
93 |
int r; |
|
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
94 |
int32 ret; |
0 | 95 |
|
863
6a1444534f62
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
96 |
assert(tile < MapSize()); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
97 |
|
4068 | 98 |
r = TerraformAllowTileProcess(ts, tile); |
99 |
if (r <= 0) return r; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
100 |
|
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
101 |
if (IsTileType(tile, MP_RAILWAY)) { |
4068 | 102 |
static const TrackBits safe_track[] = { TRACK_BIT_LOWER, TRACK_BIT_LEFT, TRACK_BIT_UPPER, TRACK_BIT_RIGHT }; |
103 |
static const Slope unsafe_slope[] = { SLOPE_S, SLOPE_W, SLOPE_N, SLOPE_E }; |
|
0 | 104 |
|
4069
d713eee28ef1
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
105 |
Slope tileh; |
d713eee28ef1
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
106 |
uint z; |
d713eee28ef1
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
107 |
|
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
108 |
// Nothing could be built at the steep slope - this avoids a bug |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
109 |
// when you have a single diagonal track in one corner on a |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
110 |
// basement and then you raise/lower the other corner. |
4069
d713eee28ef1
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
111 |
tileh = GetTileSlope(tile, &z); |
4068 | 112 |
if (tileh == unsafe_slope[mode] || |
113 |
tileh == ComplementSlope(unsafe_slope[mode])) { |
|
2686
609f3b4d2fd4
(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
|
114 |
_terraform_err_tile = tile; |
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
115 |
_error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK; |
2686
609f3b4d2fd4
(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
|
116 |
return -1; |
609f3b4d2fd4
(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
|
117 |
} |
609f3b4d2fd4
(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
|
118 |
|
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
119 |
// If we have a single diagonal track there, the other side of |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
120 |
// tile can be terraformed. |
4068 | 121 |
if (IsPlainRailTile(tile) && GetTrackBits(tile) == safe_track[mode]) { |
4069
d713eee28ef1
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
122 |
/* If terraforming downwards prevent damaging a potential tunnel below. |
d713eee28ef1
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
123 |
* This check is only necessary for flat tiles, because if the tile is |
d713eee28ef1
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
124 |
* non-flat, then the corner opposing the rail is raised. Only this corner |
d713eee28ef1
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
125 |
* can be lowered and this is a safe action |
d713eee28ef1
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
126 |
*/ |
d713eee28ef1
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
127 |
if (tileh == SLOPE_FLAT && |
d713eee28ef1
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
128 |
ts->direction == -1 && |
d713eee28ef1
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
129 |
IsTunnelInWay(tile, z - TILE_HEIGHT)) { |
d713eee28ef1
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
130 |
_terraform_err_tile = tile; |
d713eee28ef1
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
131 |
_error_message = STR_1002_EXCAVATION_WOULD_DAMAGE; |
d713eee28ef1
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
132 |
return -1; |
d713eee28ef1
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
133 |
} |
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
134 |
return 0; |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
135 |
} |
0 | 136 |
} |
137 |
||
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
138 |
ret = DoCommand(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR); |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
139 |
|
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
140 |
if (ret == CMD_ERROR) { |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
141 |
_terraform_err_tile = tile; |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
142 |
return -1; |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
143 |
} |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
144 |
|
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
145 |
ts->cost += ret; |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
146 |
|
2639 | 147 |
if (ts->tile_table_count >= 625) return -1; |
0 | 148 |
ts->tile_table[ts->tile_table_count++] = tile; |
149 |
||
150 |
return 0; |
|
151 |
} |
|
152 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
153 |
static bool TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height) |
0 | 154 |
{ |
155 |
int nh; |
|
156 |
TerraformerHeightMod *mod; |
|
157 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
158 |
|
863
6a1444534f62
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
159 |
assert(tile < MapSize()); |
0 | 160 |
|
161 |
if (height < 0) { |
|
162 |
_error_message = STR_1003_ALREADY_AT_SEA_LEVEL; |
|
163 |
return false; |
|
164 |
} |
|
165 |
||
166 |
_error_message = STR_1004_TOO_HIGH; |
|
167 |
||
2639 | 168 |
if (height > 15) return false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
169 |
|
0 | 170 |
nh = TerraformGetHeightOfTile(ts, tile); |
2639 | 171 |
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
|
172 |
|
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
173 |
if (TerraformProc(ts, tile, 0) < 0) return false; |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
174 |
if (TerraformProc(ts, tile + TileDiffXY( 0, -1), 1) < 0) return false; |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
175 |
if (TerraformProc(ts, tile + TileDiffXY(-1, -1), 2) < 0) return false; |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
176 |
if (TerraformProc(ts, tile + TileDiffXY(-1, 0), 3) < 0) return false; |
0 | 177 |
|
178 |
mod = ts->modheight; |
|
179 |
count = ts->modheight_count; |
|
180 |
||
2639 | 181 |
for (;;) { |
0 | 182 |
if (count == 0) { |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
183 |
if (ts->modheight_count >= 576) return false; |
0 | 184 |
ts->modheight_count++; |
185 |
break; |
|
186 |
} |
|
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
187 |
if (mod->tile == tile) break; |
0 | 188 |
mod++; |
189 |
count--; |
|
190 |
} |
|
191 |
||
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
192 |
mod->tile = tile; |
0 | 193 |
mod->height = (byte)height; |
194 |
||
195 |
ts->cost += _price.terraform; |
|
196 |
||
197 |
{ |
|
198 |
int direction = ts->direction, r; |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
199 |
const TileIndexDiffC *ttm; |
0 | 200 |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
201 |
static const TileIndexDiffC _terraform_tilepos[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
202 |
{ 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
203 |
{-2, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
204 |
{ 1, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
205 |
{ 0, -2} |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
206 |
}; |
0 | 207 |
|
2952 | 208 |
for (ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) { |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
209 |
tile += ToTileIndexDiff(*ttm); |
0 | 210 |
|
211 |
r = TerraformGetHeightOfTile(ts, tile); |
|
212 |
if (r != height && r-direction != height && r+direction != height) { |
|
213 |
if (!TerraformTileHeight(ts, tile, r+direction)) |
|
214 |
return false; |
|
215 |
} |
|
216 |
} |
|
217 |
} |
|
218 |
||
219 |
return true; |
|
220 |
} |
|
221 |
||
1775
548dc04d50e2
(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
|
222 |
/** Terraform land |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
223 |
* @param tile tile to terraform |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
224 |
* @param p1 corners to terraform. |
1775
548dc04d50e2
(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
|
225 |
* @param p2 direction; eg up or down |
0 | 226 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
227 |
int32 CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 228 |
{ |
229 |
TerraformerState ts; |
|
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
230 |
TileIndex t; |
0 | 231 |
int direction; |
232 |
||
233 |
TerraformerHeightMod modheight_data[576]; |
|
234 |
TileIndex tile_table_data[625]; |
|
235 |
||
236 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
237 |
||
238 |
_terraform_err_tile = 0; |
|
239 |
||
240 |
ts.direction = direction = p2 ? 1 : -1; |
|
241 |
ts.flags = flags; |
|
242 |
ts.modheight_count = ts.tile_table_count = 0; |
|
243 |
ts.cost = 0; |
|
244 |
ts.modheight = modheight_data; |
|
245 |
ts.tile_table = tile_table_data; |
|
246 |
||
1878
980fabc7d8a5
(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
|
247 |
/* Make an extra check for map-bounds cause we add tiles to the originating tile */ |
2934
3f29a7212713
(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
|
248 |
if (tile + TileDiffXY(1, 1) >= MapSize()) return CMD_ERROR; |
1878
980fabc7d8a5
(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
|
249 |
|
0 | 250 |
if (p1 & 1) { |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
251 |
t = tile + TileDiffXY(1, 0); |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
252 |
if (!TerraformTileHeight(&ts, t, TileHeight(t) + direction)) { |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
253 |
return CMD_ERROR; |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
254 |
} |
0 | 255 |
} |
256 |
||
257 |
if (p1 & 2) { |
|
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
258 |
t = tile + TileDiffXY(1, 1); |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
259 |
if (!TerraformTileHeight(&ts, t, TileHeight(t) + direction)) { |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
260 |
return CMD_ERROR; |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
261 |
} |
0 | 262 |
} |
263 |
||
264 |
if (p1 & 4) { |
|
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
265 |
t = tile + TileDiffXY(0, 1); |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
266 |
if (!TerraformTileHeight(&ts, t, TileHeight(t) + direction)) { |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
267 |
return CMD_ERROR; |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
268 |
} |
0 | 269 |
} |
270 |
||
271 |
if (p1 & 8) { |
|
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
272 |
t = tile + TileDiffXY(0, 0); |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
273 |
if (!TerraformTileHeight(&ts, t, TileHeight(t) + direction)) { |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
274 |
return CMD_ERROR; |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
275 |
} |
0 | 276 |
} |
277 |
||
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
278 |
if (direction == -1) { |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
279 |
/* Check if tunnel would take damage */ |
0 | 280 |
int count; |
281 |
TileIndex *ti = ts.tile_table; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
282 |
|
1775
548dc04d50e2
(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
|
283 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
284 |
uint z, t; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
285 |
TileIndex tile = *ti; |
0 | 286 |
|
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
287 |
z = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
288 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
289 |
if (t <= z) z = t; |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
290 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
291 |
if (t <= z) z = t; |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
292 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
293 |
if (t <= z) z = t; |
3279
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
294 |
|
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
295 |
if (IsTunnelInWay(tile, z * TILE_HEIGHT)) { |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
296 |
return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); |
2639 | 297 |
} |
0 | 298 |
} |
299 |
} |
|
300 |
||
301 |
if (flags & DC_EXEC) { |
|
302 |
/* Clear the landscape at the tiles */ |
|
303 |
{ |
|
304 |
int count; |
|
305 |
TileIndex *ti = ts.tile_table; |
|
1775
548dc04d50e2
(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
|
306 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
307 |
DoCommand(*ti, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
0 | 308 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
309 |
} |
0 | 310 |
|
311 |
/* change the height */ |
|
312 |
{ |
|
313 |
int count; |
|
314 |
TerraformerHeightMod *mod; |
|
315 |
||
316 |
mod = ts.modheight; |
|
1775
548dc04d50e2
(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
|
317 |
for (count = ts.modheight_count; count != 0; count--, mod++) { |
1979
82d8bcc16ce2
(svn r2485) Missed two uint -> TileIndex, thanks _Luca_
tron
parents:
1977
diff
changeset
|
318 |
TileIndex til = mod->tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
319 |
|
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
320 |
SetTileHeight(til, mod->height); |
0 | 321 |
TerraformAddDirtyTileAround(&ts, til); |
322 |
} |
|
323 |
} |
|
324 |
||
325 |
/* finally mark the dirty tiles dirty */ |
|
326 |
{ |
|
327 |
int count; |
|
328 |
TileIndex *ti = ts.tile_table; |
|
1775
548dc04d50e2
(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
|
329 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 330 |
MarkTileDirtyByTile(*ti); |
331 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
332 |
} |
0 | 333 |
} |
334 |
return ts.cost; |
|
335 |
} |
|
336 |
||
337 |
||
1796
614d996f6be7
(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
|
338 |
/** Levels a selected (rectangle) area of land |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
339 |
* @param tile end tile of area-drag |
1796
614d996f6be7
(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
|
340 |
* @param p1 start tile of area drag |
614d996f6be7
(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 |
* @param p2 unused |
0 | 342 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
343 |
int32 CmdLevelLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 344 |
{ |
345 |
int size_x, size_y; |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
346 |
int ex; |
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
347 |
int ey; |
0 | 348 |
int sx, sy; |
349 |
uint h, curh; |
|
350 |
int32 ret, cost, money; |
|
351 |
||
2934
3f29a7212713
(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
|
352 |
if (p1 >= MapSize()) return CMD_ERROR; |
1796
614d996f6be7
(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 |
|
889
64d2f7d5f02b
(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
|
354 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
64d2f7d5f02b
(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
|
355 |
|
0 | 356 |
// remember level height |
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
357 |
h = TileHeight(p1); |
0 | 358 |
|
359 |
// make sure sx,sy are smaller than ex,ey |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
360 |
ex = TileX(tile); |
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
361 |
ey = TileY(tile); |
926
a6d140a6a4de
(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
|
362 |
sx = TileX(p1); |
a6d140a6a4de
(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
|
363 |
sy = TileY(p1); |
0 | 364 |
if (ex < sx) intswap(ex, sx); |
365 |
if (ey < sy) intswap(ey, sy); |
|
1981 | 366 |
tile = TileXY(sx, sy); |
0 | 367 |
|
368 |
size_x = ex-sx+1; |
|
369 |
size_y = ey-sy+1; |
|
370 |
||
371 |
money = GetAvailableMoneyForCommand(); |
|
372 |
cost = 0; |
|
373 |
||
1796
614d996f6be7
(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
|
374 |
BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) { |
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
375 |
curh = TileHeight(tile2); |
0 | 376 |
while (curh != h) { |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
377 |
ret = DoCommand(tile2, 8, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND); |
1796
614d996f6be7
(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
|
378 |
if (CmdFailed(ret)) break; |
0 | 379 |
cost += ret; |
380 |
||
381 |
if (flags & DC_EXEC) { |
|
382 |
if ((money -= ret) < 0) { |
|
383 |
_additional_cash_required = ret; |
|
384 |
return cost - ret; |
|
385 |
} |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
386 |
DoCommand(tile2, 8, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND); |
0 | 387 |
} |
388 |
||
389 |
curh += (curh > h) ? -1 : 1; |
|
390 |
} |
|
1796
614d996f6be7
(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
|
391 |
} END_TILE_LOOP(tile2, size_x, size_y, tile) |
0 | 392 |
|
1796
614d996f6be7
(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
|
393 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 394 |
} |
395 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
396 |
/** Purchase a land area. Actually you only purchase one tile, so |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
397 |
* the name is a bit confusing ;p |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
398 |
* @param tile the tile the player is purchasing |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
399 |
* @param p1 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
400 |
* @param p2 unused |
0 | 401 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
402 |
int32 CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 403 |
{ |
404 |
int32 cost; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
405 |
|
0 | 406 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
407 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
408 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 409 |
|
3310
a19f247b75b6
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
410 |
if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_player)) { |
0 | 411 |
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT); |
3310
a19f247b75b6
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
412 |
} |
0 | 413 |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
414 |
cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
415 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 416 |
|
417 |
if (flags & DC_EXEC) { |
|
3310
a19f247b75b6
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
418 |
MakeOwnedLand(tile, _current_player); |
a19f247b75b6
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
419 |
MarkTileDirtyByTile(tile); |
0 | 420 |
} |
421 |
||
422 |
return cost + _price.purchase_land * 10; |
|
423 |
} |
|
424 |
||
425 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
426 |
static int32 ClearTile_Clear(TileIndex tile, byte flags) |
1095 | 427 |
{ |
2220 | 428 |
static const int32* clear_price_table[] = { |
429 |
&_price.clear_1, |
|
430 |
&_price.purchase_land, |
|
431 |
&_price.clear_2, |
|
432 |
&_price.clear_3, |
|
433 |
&_price.purchase_land, |
|
434 |
&_price.purchase_land, |
|
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
435 |
&_price.clear_2, // XXX unused? |
0 | 436 |
}; |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
437 |
int32 price; |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
438 |
|
3447 | 439 |
if (IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) == 0) { |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
440 |
price = 0; |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
441 |
} else { |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
442 |
price = *clear_price_table[GetClearGround(tile)]; |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
443 |
} |
0 | 444 |
|
2220 | 445 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 446 |
|
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
447 |
return price; |
0 | 448 |
} |
449 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
450 |
/** Sell a land area. Actually you only sell one tile, so |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
451 |
* the name is a bit confusing ;p |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
452 |
* @param tile the tile the player is selling |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
453 |
* @param p1 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
454 |
* @param p2 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
455 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
456 |
int32 CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 457 |
{ |
458 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
459 |
||
3310
a19f247b75b6
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
460 |
if (!IsOwnedLandTile(tile)) return CMD_ERROR; |
1878
980fabc7d8a5
(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
|
461 |
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR; |
980fabc7d8a5
(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
|
462 |
|
0 | 463 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
464 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 465 |
|
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
466 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 467 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
468 |
return - _price.purchase_land * 2; |
0 | 469 |
} |
470 |
||
471 |
||
472 |
#include "table/clear_land.h" |
|
473 |
||
474 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
475 |
void DrawClearLandTile(const TileInfo *ti, byte set) |
0 | 476 |
{ |
2517
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
477 |
DrawGroundSprite(SPR_FLAT_BARE_LAND + _tileh_to_sprite[ti->tileh] + set * 19); |
0 | 478 |
} |
479 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
480 |
void DrawHillyLandTile(const TileInfo *ti) |
0 | 481 |
{ |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
482 |
if (ti->tileh != SLOPE_FLAT) { |
2517
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
483 |
DrawGroundSprite(SPR_FLAT_ROUGH_LAND + _tileh_to_sprite[ti->tileh]); |
0 | 484 |
} else { |
2140
a04d0142ad65
(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
|
485 |
DrawGroundSprite(_landscape_clear_sprites[GB(ti->x ^ ti->y, 4, 3)]); |
0 | 486 |
} |
487 |
} |
|
488 |
||
2220 | 489 |
void DrawClearLandFence(const TileInfo *ti) |
0 | 490 |
{ |
491 |
byte z = ti->z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
492 |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
493 |
if (ti->tileh & SLOPE_S) { |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
494 |
z += TILE_HEIGHT; |
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
495 |
if (ti->tileh == SLOPE_STEEP_S) z += TILE_HEIGHT; |
0 | 496 |
} |
497 |
||
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
498 |
if (GetFenceSW(ti->tile) != 0) { |
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
499 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSW(ti->tile) - 1] + _fence_mod_by_tileh[ti->tileh], ti->x, ti->y, z); |
0 | 500 |
} |
501 |
||
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
502 |
if (GetFenceSE(ti->tile) != 0) { |
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
503 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSE(ti->tile) - 1] + _fence_mod_by_tileh_2[ti->tileh], ti->x, ti->y, z); |
0 | 504 |
} |
505 |
} |
|
506 |
||
507 |
static void DrawTile_Clear(TileInfo *ti) |
|
508 |
{ |
|
3166
91e9fc028c95
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
509 |
switch (GetClearGround(ti->tile)) { |
3447 | 510 |
case CLEAR_GRASS: |
3166
91e9fc028c95
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
511 |
DrawClearLandTile(ti, GetClearDensity(ti->tile)); |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
512 |
break; |
0 | 513 |
|
3447 | 514 |
case CLEAR_ROUGH: |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
515 |
DrawHillyLandTile(ti); |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
516 |
break; |
0 | 517 |
|
3447 | 518 |
case CLEAR_ROCKS: |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
519 |
DrawGroundSprite(SPR_FLAT_ROCKY_LAND_1 + _tileh_to_sprite[ti->tileh]); |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
520 |
break; |
0 | 521 |
|
3447 | 522 |
case CLEAR_FIELDS: |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
523 |
DrawGroundSprite(_clear_land_sprites_1[GetFieldType(ti->tile)] + _tileh_to_sprite[ti->tileh]); |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
524 |
break; |
0 | 525 |
|
3447 | 526 |
case CLEAR_SNOW: |
3166
91e9fc028c95
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
527 |
DrawGroundSprite(_clear_land_sprites_2[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh]); |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
528 |
break; |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
529 |
|
3447 | 530 |
case CLEAR_DESERT: |
3166
91e9fc028c95
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
531 |
DrawGroundSprite(_clear_land_sprites_3[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh]); |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
532 |
break; |
0 | 533 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
534 |
|
2220 | 535 |
DrawClearLandFence(ti); |
0 | 536 |
} |
537 |
||
4231
2823b3643862
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
538 |
static uint GetSlopeZ_Clear(TileIndex tile, uint x, uint y) |
1095 | 539 |
{ |
4231
2823b3643862
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
540 |
uint z; |
2823b3643862
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
541 |
uint tileh = GetTileSlope(tile, &z); |
2823b3643862
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
542 |
|
2823b3643862
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
543 |
return z + GetPartialZ(x & 0xF, y & 0xF, tileh); |
1095 | 544 |
} |
0 | 545 |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
546 |
static Slope GetSlopeTileh_Clear(TileIndex tile, Slope tileh) |
39 | 547 |
{ |
3418
ec9003ebf933
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3379
diff
changeset
|
548 |
return tileh; |
39 | 549 |
} |
550 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
551 |
static void GetAcceptedCargo_Clear(TileIndex tile, AcceptedCargo ac) |
0 | 552 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
553 |
/* unused */ |
0 | 554 |
} |
555 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
556 |
static void AnimateTile_Clear(TileIndex tile) |
0 | 557 |
{ |
558 |
/* unused */ |
|
559 |
} |
|
560 |
||
1293 | 561 |
void TileLoopClearHelper(TileIndex tile) |
0 | 562 |
{ |
2221
de4a862fa8e2
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
563 |
byte self; |
de4a862fa8e2
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
564 |
byte neighbour; |
1293 | 565 |
TileIndex dirty = INVALID_TILE; |
0 | 566 |
|
3447 | 567 |
self = (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_FIELDS)); |
0 | 568 |
|
3447 | 569 |
neighbour = (IsTileType(TILE_ADDXY(tile, 1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 1, 0), CLEAR_FIELDS)); |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
570 |
if (GetFenceSW(tile) == 0) { |
2221
de4a862fa8e2
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
571 |
if (self != neighbour) { |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
572 |
SetFenceSW(tile, 3); |
0 | 573 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
574 |
} |
0 | 575 |
} else { |
2221
de4a862fa8e2
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
576 |
if (self == 0 && neighbour == 0) { |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
577 |
SetFenceSW(tile, 0); |
0 | 578 |
dirty = tile; |
579 |
} |
|
580 |
} |
|
581 |
||
3447 | 582 |
neighbour = (IsTileType(TILE_ADDXY(tile, 0, 1), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 0, 1), CLEAR_FIELDS)); |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
583 |
if (GetFenceSE(tile) == 0) { |
2221
de4a862fa8e2
(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 != neighbour) { |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
585 |
SetFenceSE(tile, 3); |
0 | 586 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
587 |
} |
0 | 588 |
} else { |
2221
de4a862fa8e2
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
589 |
if (self == 0 && neighbour == 0) { |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
590 |
SetFenceSE(tile, 0); |
0 | 591 |
dirty = tile; |
592 |
} |
|
593 |
} |
|
594 |
||
2221
de4a862fa8e2
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
595 |
if (dirty != INVALID_TILE) MarkTileDirtyByTile(dirty); |
0 | 596 |
} |
597 |
||
598 |
||
599 |
/* convert into snowy tiles */ |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
600 |
static void TileLoopClearAlps(TileIndex tile) |
0 | 601 |
{ |
4157
8d0051fdde68
(svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents:
4069
diff
changeset
|
602 |
int k = GetTileZ(tile) - _opt.snow_line + TILE_HEIGHT; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
603 |
|
4157
8d0051fdde68
(svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents:
4069
diff
changeset
|
604 |
if (k < 0) { // well below the snow line |
3447 | 605 |
if (!IsClearGround(tile, CLEAR_SNOW)) return; |
606 |
if (GetClearDensity(tile) == 0) SetClearGroundDensity(tile, CLEAR_GRASS, 3); |
|
0 | 607 |
} else { |
3447 | 608 |
if (!IsClearGround(tile, CLEAR_SNOW)) { |
609 |
SetClearGroundDensity(tile, CLEAR_SNOW, 0); |
|
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
610 |
} else { |
4157
8d0051fdde68
(svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents:
4069
diff
changeset
|
611 |
uint density = min((uint)k / TILE_HEIGHT, 3); |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
612 |
|
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
613 |
if (GetClearDensity(tile) < density) { |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
614 |
AddClearDensity(tile, 1); |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
615 |
} else if (GetClearDensity(tile) > density) { |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
616 |
AddClearDensity(tile, -1); |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
617 |
} else { |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
618 |
return; |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
619 |
} |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
620 |
} |
0 | 621 |
} |
622 |
||
623 |
MarkTileDirtyByTile(tile); |
|
624 |
} |
|
625 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
626 |
static void TileLoopClearDesert(TileIndex tile) |
0 | 627 |
{ |
3447 | 628 |
if (IsClearGround(tile, CLEAR_DESERT)) return; |
0 | 629 |
|
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3310
diff
changeset
|
630 |
if (GetTropicZone(tile) == TROPICZONE_DESERT) { |
3447 | 631 |
SetClearGroundDensity(tile, CLEAR_DESERT, 3); |
0 | 632 |
} else { |
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3310
diff
changeset
|
633 |
if (GetTropicZone(tile + TileDiffXY( 1, 0)) != TROPICZONE_DESERT && |
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3310
diff
changeset
|
634 |
GetTropicZone(tile + TileDiffXY(-1, 0)) != TROPICZONE_DESERT && |
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3310
diff
changeset
|
635 |
GetTropicZone(tile + TileDiffXY( 0, 1)) != TROPICZONE_DESERT && |
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3310
diff
changeset
|
636 |
GetTropicZone(tile + TileDiffXY( 0, -1)) != TROPICZONE_DESERT) |
1981 | 637 |
return; |
3447 | 638 |
SetClearGroundDensity(tile, CLEAR_DESERT, 1); |
0 | 639 |
} |
640 |
||
641 |
MarkTileDirtyByTile(tile); |
|
642 |
} |
|
643 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
644 |
static void TileLoop_Clear(TileIndex tile) |
0 | 645 |
{ |
646 |
TileLoopClearHelper(tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
647 |
|
2989 | 648 |
switch (_opt.landscape) { |
649 |
case LT_DESERT: TileLoopClearDesert(tile); break; |
|
650 |
case LT_HILLY: TileLoopClearAlps(tile); break; |
|
0 | 651 |
} |
652 |
||
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
653 |
switch (GetClearGround(tile)) { |
3447 | 654 |
case CLEAR_GRASS: |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
655 |
if (GetClearDensity(tile) == 3) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
656 |
|
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
657 |
if (_game_mode != GM_EDITOR) { |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
658 |
if (GetClearCounter(tile) < 7) { |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
659 |
AddClearCounter(tile, 1); |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
660 |
return; |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
661 |
} else { |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
662 |
SetClearCounter(tile, 0); |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
663 |
AddClearDensity(tile, 1); |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
664 |
} |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
665 |
} else { |
3447 | 666 |
SetClearGroundDensity(tile, GB(Random(), 0, 8) > 21 ? CLEAR_GRASS : CLEAR_ROUGH, 3); |
0 | 667 |
} |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
668 |
break; |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
669 |
|
3447 | 670 |
case CLEAR_FIELDS: { |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
671 |
uint field_type; |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
672 |
|
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
673 |
if (_game_mode == GM_EDITOR) return; |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
674 |
|
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
675 |
if (GetClearCounter(tile) < 7) { |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
676 |
AddClearCounter(tile, 1); |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
677 |
return; |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
678 |
} else { |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
679 |
SetClearCounter(tile, 0); |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
680 |
} |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
681 |
|
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
682 |
field_type = GetFieldType(tile); |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
683 |
field_type = (field_type < 8) ? field_type + 1 : 0; |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
684 |
SetFieldType(tile, field_type); |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
685 |
break; |
0 | 686 |
} |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
687 |
|
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
688 |
default: |
0 | 689 |
return; |
690 |
} |
|
691 |
||
692 |
MarkTileDirtyByTile(tile); |
|
693 |
} |
|
694 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
695 |
void GenerateClearTile(void) |
0 | 696 |
{ |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
697 |
uint i, gi; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
698 |
TileIndex tile; |
0 | 699 |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
700 |
/* add rough tiles */ |
2635 | 701 |
i = ScaleByMapSize(GB(Random(), 0, 10) + 0x400); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
702 |
gi = ScaleByMapSize(GB(Random(), 0, 7) + 0x80); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
703 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
704 |
SetGeneratingWorldProgress(GWP_ROUGH_ROCKY, gi + i); |
0 | 705 |
do { |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
706 |
IncreaseGeneratingWorldProgress(GWP_ROUGH_ROCKY); |
2051 | 707 |
tile = RandomTile(); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
708 |
if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_DESERT)) SetClearGroundDensity(tile, CLEAR_ROUGH, 3); |
0 | 709 |
} while (--i); |
710 |
||
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
711 |
/* add rocky tiles */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
712 |
i = gi; |
0 | 713 |
do { |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
714 |
uint32 r = Random(); |
2051 | 715 |
tile = RandomTileSeed(r); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
716 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
717 |
IncreaseGeneratingWorldProgress(GWP_ROUGH_ROCKY); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
718 |
if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_DESERT)) { |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
719 |
uint j = GB(r, 16, 4) + 5; |
2951 | 720 |
for (;;) { |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
721 |
TileIndex tile_new; |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
722 |
|
3447 | 723 |
SetClearGroundDensity(tile, CLEAR_ROCKS, 3); |
0 | 724 |
do { |
725 |
if (--j == 0) goto get_out; |
|
2635 | 726 |
tile_new = tile + TileOffsByDir(GB(Random(), 0, 2)); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
727 |
} while (!IsTileType(tile_new, MP_CLEAR) || IsClearGround(tile_new, CLEAR_DESERT)); |
0 | 728 |
tile = tile_new; |
729 |
} |
|
730 |
get_out:; |
|
731 |
} |
|
732 |
} while (--i); |
|
733 |
} |
|
734 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
735 |
static void ClickTile_Clear(TileIndex tile) |
0 | 736 |
{ |
737 |
/* not used */ |
|
738 |
} |
|
739 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
740 |
static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode) |
0 | 741 |
{ |
742 |
return 0; |
|
743 |
} |
|
744 |
||
2220 | 745 |
static const StringID _clear_land_str[] = { |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
746 |
STR_080D_GRASS, |
0 | 747 |
STR_080B_ROUGH_LAND, |
748 |
STR_080A_ROCKS, |
|
749 |
STR_080E_FIELDS, |
|
750 |
STR_080F_SNOW_COVERED_LAND, |
|
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
751 |
STR_0810_DESERT |
0 | 752 |
}; |
753 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
754 |
static void GetTileDesc_Clear(TileIndex tile, TileDesc *td) |
0 | 755 |
{ |
3447 | 756 |
if (IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) == 0) { |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
757 |
td->str = STR_080C_BARE_LAND; |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
758 |
} else { |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
759 |
td->str = _clear_land_str[GetClearGround(tile)]; |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
760 |
} |
1901
03bf9bf99319
(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
|
761 |
td->owner = GetTileOwner(tile); |
0 | 762 |
} |
763 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
764 |
static void ChangeTileOwner_Clear(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 765 |
{ |
766 |
return; |
|
767 |
} |
|
768 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
769 |
void InitializeClearLand(void) |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
770 |
{ |
3422
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3418
diff
changeset
|
771 |
_opt.snow_line = _patches.snow_line_height * TILE_HEIGHT; |
0 | 772 |
} |
773 |
||
774 |
const TileTypeProcs _tile_type_clear_procs = { |
|
775 |
DrawTile_Clear, /* draw_tile_proc */ |
|
776 |
GetSlopeZ_Clear, /* get_slope_z_proc */ |
|
777 |
ClearTile_Clear, /* clear_tile_proc */ |
|
778 |
GetAcceptedCargo_Clear, /* get_accepted_cargo_proc */ |
|
779 |
GetTileDesc_Clear, /* get_tile_desc_proc */ |
|
780 |
GetTileTrackStatus_Clear, /* get_tile_track_status_proc */ |
|
781 |
ClickTile_Clear, /* click_tile_proc */ |
|
782 |
AnimateTile_Clear, /* animate_tile_proc */ |
|
783 |
TileLoop_Clear, /* tile_loop_clear */ |
|
784 |
ChangeTileOwner_Clear, /* change_tile_owner_clear */ |
|
785 |
NULL, /* get_produced_cargo_proc */ |
|
786 |
NULL, /* vehicle_enter_tile_proc */ |
|
39 | 787 |
GetSlopeTileh_Clear, /* get_slope_tileh_proc */ |
0 | 788 |
}; |