author | Darkvater |
Sun, 10 Dec 2006 00:20:26 +0000 | |
changeset 5305 | e07957fe871e |
parent 4815 | c2a54b213fde |
child 5513 | 0d3227e250eb |
child 5573 | afa6f92a71fd |
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" |
3144
426b825578f9
(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
caf4fcb4e05b
(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
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
473
diff
changeset
|
7 |
#include "table/strings.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2154
diff
changeset
|
8 |
#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
|
9 |
#include "map.h" |
2154
63a6b880b4c0
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2153
diff
changeset
|
10 |
#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
|
11 |
#include "tile.h" |
0 | 12 |
#include "viewport.h" |
13 |
#include "command.h" |
|
3156
028b6756b279
(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
91e89aa8c299
(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
b90693227193
(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
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
17 |
#include "unmovable_map.h" |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
18 |
#include "genworld.h" |
4328
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4300
diff
changeset
|
19 |
#include "industry.h" |
0 | 20 |
|
21 |
typedef struct TerraformerHeightMod { |
|
22 |
TileIndex tile; |
|
23 |
byte height; |
|
24 |
} TerraformerHeightMod; |
|
25 |
||
26 |
typedef struct TerraformerState { |
|
27 |
int height[4]; |
|
28 |
uint32 flags; |
|
29 |
||
30 |
int direction; |
|
31 |
int modheight_count; |
|
32 |
int tile_table_count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
33 |
|
0 | 34 |
int32 cost; |
35 |
||
36 |
TileIndex *tile_table; |
|
37 |
TerraformerHeightMod *modheight; |
|
38 |
||
39 |
} TerraformerState; |
|
40 |
||
41 |
static int TerraformAllowTileProcess(TerraformerState *ts, TileIndex tile) |
|
42 |
{ |
|
43 |
TileIndex *t; |
|
44 |
int count; |
|
45 |
||
2639 | 46 |
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return -1; |
0 | 47 |
|
48 |
t = ts->tile_table; |
|
2639 | 49 |
for (count = ts->tile_table_count; count != 0; count--, t++) { |
50 |
if (*t == tile) return 0; |
|
0 | 51 |
} |
52 |
||
53 |
return 1; |
|
54 |
} |
|
55 |
||
56 |
static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile) |
|
57 |
{ |
|
58 |
TerraformerHeightMod *mod = ts->modheight; |
|
59 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
60 |
|
2639 | 61 |
for (count = ts->modheight_count; count != 0; count--, mod++) { |
62 |
if (mod->tile == tile) return mod->height; |
|
0 | 63 |
} |
64 |
||
1044
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
65 |
return TileHeight(tile); |
0 | 66 |
} |
67 |
||
68 |
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile) |
|
69 |
{ |
|
70 |
int count; |
|
71 |
TileIndex *t; |
|
72 |
||
73 |
count = ts->tile_table_count; |
|
74 |
||
2639 | 75 |
if (count >= 625) return; |
0 | 76 |
|
2952 | 77 |
for (t = ts->tile_table; count != 0; count--,t++) { |
2639 | 78 |
if (*t == tile) return; |
0 | 79 |
} |
80 |
||
81 |
ts->tile_table[ts->tile_table_count++] = tile; |
|
82 |
} |
|
83 |
||
84 |
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile) |
|
85 |
{ |
|
1981 | 86 |
TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1)); |
87 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1)); |
|
88 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0)); |
|
0 | 89 |
TerraformAddDirtyTile(ts, tile); |
90 |
} |
|
91 |
||
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
92 |
static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode) |
0 | 93 |
{ |
94 |
int r; |
|
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
95 |
int32 ret; |
0 | 96 |
|
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
97 |
assert(tile < MapSize()); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
98 |
|
4068 | 99 |
r = TerraformAllowTileProcess(ts, tile); |
100 |
if (r <= 0) return r; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
101 |
|
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
102 |
if (IsTileType(tile, MP_RAILWAY)) { |
4068 | 103 |
static const TrackBits safe_track[] = { TRACK_BIT_LOWER, TRACK_BIT_LEFT, TRACK_BIT_UPPER, TRACK_BIT_RIGHT }; |
104 |
static const Slope unsafe_slope[] = { SLOPE_S, SLOPE_W, SLOPE_N, SLOPE_E }; |
|
0 | 105 |
|
4069
d2139f621c74
(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 |
Slope tileh; |
d2139f621c74
(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 |
uint z; |
d2139f621c74
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
108 |
|
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
109 |
// Nothing could be built at the steep slope - this avoids a bug |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
110 |
// when you have a single diagonal track in one corner on a |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
111 |
// basement and then you raise/lower the other corner. |
4069
d2139f621c74
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
112 |
tileh = GetTileSlope(tile, &z); |
4068 | 113 |
if (tileh == unsafe_slope[mode] || |
114 |
tileh == ComplementSlope(unsafe_slope[mode])) { |
|
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
|
115 |
_terraform_err_tile = tile; |
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
116 |
_error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK; |
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
|
117 |
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
|
118 |
} |
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
|
119 |
|
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
120 |
// If we have a single diagonal track there, the other side of |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
121 |
// tile can be terraformed. |
4068 | 122 |
if (IsPlainRailTile(tile) && GetTrackBits(tile) == safe_track[mode]) { |
4069
d2139f621c74
(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 |
/* If terraforming downwards prevent damaging a potential tunnel below. |
d2139f621c74
(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 |
* This check is only necessary for flat tiles, because if the tile is |
d2139f621c74
(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 |
* non-flat, then the corner opposing the rail is raised. Only this corner |
d2139f621c74
(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 |
* can be lowered and this is a safe action |
d2139f621c74
(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 |
*/ |
d2139f621c74
(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 |
if (tileh == SLOPE_FLAT && |
d2139f621c74
(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 |
ts->direction == -1 && |
d2139f621c74
(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 |
IsTunnelInWay(tile, z - TILE_HEIGHT)) { |
d2139f621c74
(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 |
_terraform_err_tile = tile; |
d2139f621c74
(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 |
_error_message = STR_1002_EXCAVATION_WOULD_DAMAGE; |
d2139f621c74
(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 |
return -1; |
d2139f621c74
(svn r5365) -Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
tron
parents:
4068
diff
changeset
|
134 |
} |
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
135 |
return 0; |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
136 |
} |
0 | 137 |
} |
138 |
||
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
139 |
ret = DoCommand(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR); |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
140 |
|
4560
f744bf3dd85a
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4559
diff
changeset
|
141 |
if (CmdFailed(ret)) { |
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
142 |
_terraform_err_tile = tile; |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
143 |
return -1; |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
144 |
} |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
145 |
|
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
146 |
ts->cost += ret; |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
147 |
|
2639 | 148 |
if (ts->tile_table_count >= 625) return -1; |
0 | 149 |
ts->tile_table[ts->tile_table_count++] = tile; |
150 |
||
151 |
return 0; |
|
152 |
} |
|
153 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
154 |
static bool TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height) |
0 | 155 |
{ |
156 |
int nh; |
|
157 |
TerraformerHeightMod *mod; |
|
158 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
159 |
|
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
160 |
assert(tile < MapSize()); |
0 | 161 |
|
162 |
if (height < 0) { |
|
163 |
_error_message = STR_1003_ALREADY_AT_SEA_LEVEL; |
|
164 |
return false; |
|
165 |
} |
|
166 |
||
167 |
_error_message = STR_1004_TOO_HIGH; |
|
168 |
||
2639 | 169 |
if (height > 15) return false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
170 |
|
0 | 171 |
nh = TerraformGetHeightOfTile(ts, tile); |
2639 | 172 |
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
|
173 |
|
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
174 |
if (TerraformProc(ts, tile, 0) < 0) return false; |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
175 |
if (TerraformProc(ts, tile + TileDiffXY( 0, -1), 1) < 0) return false; |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
176 |
if (TerraformProc(ts, tile + TileDiffXY(-1, -1), 2) < 0) return false; |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
177 |
if (TerraformProc(ts, tile + TileDiffXY(-1, 0), 3) < 0) return false; |
0 | 178 |
|
179 |
mod = ts->modheight; |
|
180 |
count = ts->modheight_count; |
|
181 |
||
2639 | 182 |
for (;;) { |
0 | 183 |
if (count == 0) { |
4000
bab1ebc37da0
(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
|
184 |
if (ts->modheight_count >= 576) return false; |
0 | 185 |
ts->modheight_count++; |
186 |
break; |
|
187 |
} |
|
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
188 |
if (mod->tile == tile) break; |
0 | 189 |
mod++; |
190 |
count--; |
|
191 |
} |
|
192 |
||
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
193 |
mod->tile = tile; |
0 | 194 |
mod->height = (byte)height; |
195 |
||
196 |
ts->cost += _price.terraform; |
|
197 |
||
198 |
{ |
|
199 |
int direction = ts->direction, r; |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
200 |
const TileIndexDiffC *ttm; |
0 | 201 |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
202 |
static const TileIndexDiffC _terraform_tilepos[] = { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
203 |
{ 1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
204 |
{-2, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
205 |
{ 1, 1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
206 |
{ 0, -2} |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
207 |
}; |
0 | 208 |
|
2952 | 209 |
for (ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) { |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
210 |
tile += ToTileIndexDiff(*ttm); |
0 | 211 |
|
212 |
r = TerraformGetHeightOfTile(ts, tile); |
|
213 |
if (r != height && r-direction != height && r+direction != height) { |
|
214 |
if (!TerraformTileHeight(ts, tile, r+direction)) |
|
215 |
return false; |
|
216 |
} |
|
217 |
} |
|
218 |
} |
|
219 |
||
220 |
return true; |
|
221 |
} |
|
222 |
||
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
|
223 |
/** Terraform land |
3491
4c8427796c64
(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
|
224 |
* @param tile tile to terraform |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
225 |
* @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
|
226 |
* @param p2 direction; eg up or down |
0 | 227 |
*/ |
3491
4c8427796c64
(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
|
228 |
int32 CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 229 |
{ |
230 |
TerraformerState ts; |
|
4000
bab1ebc37da0
(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
|
231 |
TileIndex t; |
0 | 232 |
int direction; |
233 |
||
234 |
TerraformerHeightMod modheight_data[576]; |
|
235 |
TileIndex tile_table_data[625]; |
|
236 |
||
237 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
238 |
||
239 |
_terraform_err_tile = 0; |
|
240 |
||
241 |
ts.direction = direction = p2 ? 1 : -1; |
|
242 |
ts.flags = flags; |
|
243 |
ts.modheight_count = ts.tile_table_count = 0; |
|
244 |
ts.cost = 0; |
|
245 |
ts.modheight = modheight_data; |
|
246 |
ts.tile_table = tile_table_data; |
|
247 |
||
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
|
248 |
/* 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
|
249 |
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
|
250 |
|
0 | 251 |
if (p1 & 1) { |
4000
bab1ebc37da0
(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 |
t = tile + TileDiffXY(1, 0); |
bab1ebc37da0
(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 |
if (!TerraformTileHeight(&ts, t, TileHeight(t) + direction)) { |
bab1ebc37da0
(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 |
return CMD_ERROR; |
bab1ebc37da0
(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
|
255 |
} |
0 | 256 |
} |
257 |
||
258 |
if (p1 & 2) { |
|
4000
bab1ebc37da0
(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 |
t = tile + TileDiffXY(1, 1); |
bab1ebc37da0
(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 |
if (!TerraformTileHeight(&ts, t, TileHeight(t) + direction)) { |
bab1ebc37da0
(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 |
return CMD_ERROR; |
bab1ebc37da0
(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
|
262 |
} |
0 | 263 |
} |
264 |
||
265 |
if (p1 & 4) { |
|
4000
bab1ebc37da0
(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 |
t = tile + TileDiffXY(0, 1); |
bab1ebc37da0
(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 |
if (!TerraformTileHeight(&ts, t, TileHeight(t) + direction)) { |
bab1ebc37da0
(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 |
return CMD_ERROR; |
bab1ebc37da0
(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
|
269 |
} |
0 | 270 |
} |
271 |
||
272 |
if (p1 & 8) { |
|
4000
bab1ebc37da0
(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 |
t = tile + TileDiffXY(0, 0); |
bab1ebc37da0
(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 |
if (!TerraformTileHeight(&ts, t, TileHeight(t) + direction)) { |
bab1ebc37da0
(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 |
return CMD_ERROR; |
bab1ebc37da0
(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
|
276 |
} |
0 | 277 |
} |
278 |
||
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
279 |
if (direction == -1) { |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
280 |
/* Check if tunnel would take damage */ |
0 | 281 |
int count; |
282 |
TileIndex *ti = ts.tile_table; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
283 |
|
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
|
284 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
285 |
uint z, t; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
286 |
TileIndex tile = *ti; |
0 | 287 |
|
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
288 |
z = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
289 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
290 |
if (t <= z) z = t; |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
291 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
292 |
if (t <= z) z = t; |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
293 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
294 |
if (t <= z) z = t; |
3279
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
295 |
|
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
296 |
if (IsTunnelInWay(tile, z * TILE_HEIGHT)) { |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4043
diff
changeset
|
297 |
return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); |
2639 | 298 |
} |
0 | 299 |
} |
300 |
} |
|
301 |
||
302 |
if (flags & DC_EXEC) { |
|
303 |
/* Clear the landscape at the tiles */ |
|
304 |
{ |
|
305 |
int count; |
|
306 |
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
|
307 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
3491
4c8427796c64
(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
|
308 |
DoCommand(*ti, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
0 | 309 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
310 |
} |
0 | 311 |
|
312 |
/* change the height */ |
|
313 |
{ |
|
314 |
int count; |
|
315 |
TerraformerHeightMod *mod; |
|
316 |
||
317 |
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
|
318 |
for (count = ts.modheight_count; count != 0; count--, mod++) { |
1979
f4462d4e8e62
(svn r2485) Missed two uint -> TileIndex, thanks _Luca_
tron
parents:
1977
diff
changeset
|
319 |
TileIndex til = mod->tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
320 |
|
1059
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
321 |
SetTileHeight(til, mod->height); |
0 | 322 |
TerraformAddDirtyTileAround(&ts, til); |
323 |
} |
|
324 |
} |
|
325 |
||
326 |
/* finally mark the dirty tiles dirty */ |
|
327 |
{ |
|
328 |
int count; |
|
329 |
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
|
330 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 331 |
MarkTileDirtyByTile(*ti); |
332 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
333 |
} |
0 | 334 |
} |
335 |
return ts.cost; |
|
336 |
} |
|
337 |
||
338 |
||
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
|
339 |
/** Levels a selected (rectangle) area of land |
3491
4c8427796c64
(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
|
340 |
* @param tile end tile of area-drag |
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 |
* @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
|
342 |
* @param p2 unused |
0 | 343 |
*/ |
3491
4c8427796c64
(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
|
344 |
int32 CmdLevelLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 345 |
{ |
346 |
int size_x, size_y; |
|
3491
4c8427796c64
(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 ex; |
4c8427796c64
(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
|
348 |
int ey; |
0 | 349 |
int sx, sy; |
350 |
uint h, curh; |
|
351 |
int32 ret, cost, money; |
|
352 |
||
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
|
353 |
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
|
354 |
|
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
|
355 |
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
|
356 |
|
0 | 357 |
// remember level height |
1044
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
358 |
h = TileHeight(p1); |
0 | 359 |
|
360 |
// make sure sx,sy are smaller than ex,ey |
|
3491
4c8427796c64
(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 |
ex = TileX(tile); |
4c8427796c64
(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
|
362 |
ey = TileY(tile); |
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
|
363 |
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
|
364 |
sy = TileY(p1); |
0 | 365 |
if (ex < sx) intswap(ex, sx); |
366 |
if (ey < sy) intswap(ey, sy); |
|
1981 | 367 |
tile = TileXY(sx, sy); |
0 | 368 |
|
369 |
size_x = ex-sx+1; |
|
370 |
size_y = ey-sy+1; |
|
371 |
||
372 |
money = GetAvailableMoneyForCommand(); |
|
373 |
cost = 0; |
|
374 |
||
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
|
375 |
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
|
376 |
curh = TileHeight(tile2); |
0 | 377 |
while (curh != h) { |
3491
4c8427796c64
(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
|
378 |
ret = DoCommand(tile2, 8, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND); |
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
|
379 |
if (CmdFailed(ret)) break; |
0 | 380 |
cost += ret; |
381 |
||
382 |
if (flags & DC_EXEC) { |
|
383 |
if ((money -= ret) < 0) { |
|
384 |
_additional_cash_required = ret; |
|
385 |
return cost - ret; |
|
386 |
} |
|
3491
4c8427796c64
(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
|
387 |
DoCommand(tile2, 8, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND); |
0 | 388 |
} |
389 |
||
390 |
curh += (curh > h) ? -1 : 1; |
|
391 |
} |
|
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
|
392 |
} END_TILE_LOOP(tile2, size_x, size_y, tile) |
0 | 393 |
|
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
|
394 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 395 |
} |
396 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
397 |
/** 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
|
398 |
* the name is a bit confusing ;p |
3491
4c8427796c64
(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
|
399 |
* @param tile the tile the player is purchasing |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
400 |
* @param p1 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
401 |
* @param p2 unused |
0 | 402 |
*/ |
3491
4c8427796c64
(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
|
403 |
int32 CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 404 |
{ |
405 |
int32 cost; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
406 |
|
0 | 407 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
408 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
409 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 410 |
|
3310
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
411 |
if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_player)) { |
0 | 412 |
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT); |
3310
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
413 |
} |
0 | 414 |
|
3491
4c8427796c64
(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
|
415 |
cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
416 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 417 |
|
418 |
if (flags & DC_EXEC) { |
|
3310
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
419 |
MakeOwnedLand(tile, _current_player); |
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
420 |
MarkTileDirtyByTile(tile); |
0 | 421 |
} |
422 |
||
423 |
return cost + _price.purchase_land * 10; |
|
424 |
} |
|
425 |
||
426 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
427 |
static int32 ClearTile_Clear(TileIndex tile, byte flags) |
1095 | 428 |
{ |
2220 | 429 |
static const int32* clear_price_table[] = { |
430 |
&_price.clear_1, |
|
431 |
&_price.purchase_land, |
|
432 |
&_price.clear_2, |
|
433 |
&_price.clear_3, |
|
434 |
&_price.purchase_land, |
|
435 |
&_price.purchase_land, |
|
2955
27221592ebbc
(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
|
436 |
&_price.clear_2, // XXX unused? |
0 | 437 |
}; |
2955
27221592ebbc
(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 |
int32 price; |
27221592ebbc
(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
|
439 |
|
3447 | 440 |
if (IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) == 0) { |
2955
27221592ebbc
(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 |
price = 0; |
27221592ebbc
(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 |
} else { |
27221592ebbc
(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 |
price = *clear_price_table[GetClearGround(tile)]; |
27221592ebbc
(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
|
444 |
} |
0 | 445 |
|
2220 | 446 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 447 |
|
2955
27221592ebbc
(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
|
448 |
return price; |
0 | 449 |
} |
450 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
451 |
/** 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
|
452 |
* the name is a bit confusing ;p |
3491
4c8427796c64
(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
|
453 |
* @param tile the tile the player is selling |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
454 |
* @param p1 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
455 |
* @param p2 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
456 |
*/ |
3491
4c8427796c64
(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
|
457 |
int32 CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 458 |
{ |
459 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
460 |
||
3310
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
461 |
if (!IsOwnedLandTile(tile)) 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
|
462 |
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
|
463 |
|
0 | 464 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
465 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 466 |
|
4000
bab1ebc37da0
(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
|
467 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 468 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
469 |
return - _price.purchase_land * 2; |
0 | 470 |
} |
471 |
||
472 |
||
473 |
#include "table/clear_land.h" |
|
474 |
||
475 |
||
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
|
476 |
void DrawClearLandTile(const TileInfo *ti, byte set) |
0 | 477 |
{ |
2517
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
478 |
DrawGroundSprite(SPR_FLAT_BARE_LAND + _tileh_to_sprite[ti->tileh] + set * 19); |
0 | 479 |
} |
480 |
||
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
|
481 |
void DrawHillyLandTile(const TileInfo *ti) |
0 | 482 |
{ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
483 |
if (ti->tileh != SLOPE_FLAT) { |
2517
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
484 |
DrawGroundSprite(SPR_FLAT_ROUGH_LAND + _tileh_to_sprite[ti->tileh]); |
0 | 485 |
} 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
|
486 |
DrawGroundSprite(_landscape_clear_sprites[GB(ti->x ^ ti->y, 4, 3)]); |
0 | 487 |
} |
488 |
} |
|
489 |
||
2220 | 490 |
void DrawClearLandFence(const TileInfo *ti) |
0 | 491 |
{ |
492 |
byte z = ti->z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
493 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
494 |
if (ti->tileh & SLOPE_S) { |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
495 |
z += TILE_HEIGHT; |
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
496 |
if (ti->tileh == SLOPE_STEEP_S) z += TILE_HEIGHT; |
0 | 497 |
} |
498 |
||
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
499 |
if (GetFenceSW(ti->tile) != 0) { |
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
500 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSW(ti->tile) - 1] + _fence_mod_by_tileh[ti->tileh], ti->x, ti->y, z); |
0 | 501 |
} |
502 |
||
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
503 |
if (GetFenceSE(ti->tile) != 0) { |
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
504 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSE(ti->tile) - 1] + _fence_mod_by_tileh_2[ti->tileh], ti->x, ti->y, z); |
0 | 505 |
} |
506 |
} |
|
507 |
||
508 |
static void DrawTile_Clear(TileInfo *ti) |
|
509 |
{ |
|
3166
747e74d236f0
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
510 |
switch (GetClearGround(ti->tile)) { |
3447 | 511 |
case CLEAR_GRASS: |
3166
747e74d236f0
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
512 |
DrawClearLandTile(ti, GetClearDensity(ti->tile)); |
2955
27221592ebbc
(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
|
513 |
break; |
0 | 514 |
|
3447 | 515 |
case CLEAR_ROUGH: |
2955
27221592ebbc
(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 |
DrawHillyLandTile(ti); |
27221592ebbc
(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
|
517 |
break; |
0 | 518 |
|
3447 | 519 |
case CLEAR_ROCKS: |
2955
27221592ebbc
(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 |
DrawGroundSprite(SPR_FLAT_ROCKY_LAND_1 + _tileh_to_sprite[ti->tileh]); |
27221592ebbc
(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
|
521 |
break; |
0 | 522 |
|
3447 | 523 |
case CLEAR_FIELDS: |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
524 |
DrawGroundSprite(_clear_land_sprites_1[GetFieldType(ti->tile)] + _tileh_to_sprite[ti->tileh]); |
2955
27221592ebbc
(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
|
525 |
break; |
0 | 526 |
|
3447 | 527 |
case CLEAR_SNOW: |
3166
747e74d236f0
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
528 |
DrawGroundSprite(_clear_land_sprites_2[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh]); |
2955
27221592ebbc
(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 |
break; |
27221592ebbc
(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
|
530 |
|
3447 | 531 |
case CLEAR_DESERT: |
3166
747e74d236f0
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
532 |
DrawGroundSprite(_clear_land_sprites_3[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh]); |
2955
27221592ebbc
(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
|
533 |
break; |
0 | 534 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
535 |
|
2220 | 536 |
DrawClearLandFence(ti); |
0 | 537 |
} |
538 |
||
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
539 |
static uint GetSlopeZ_Clear(TileIndex tile, uint x, uint y) |
1095 | 540 |
{ |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
541 |
uint z; |
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
542 |
uint tileh = GetTileSlope(tile, &z); |
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
543 |
|
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
544 |
return z + GetPartialZ(x & 0xF, y & 0xF, tileh); |
1095 | 545 |
} |
0 | 546 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
547 |
static Slope GetSlopeTileh_Clear(TileIndex tile, Slope tileh) |
39 | 548 |
{ |
3418
a592d40a4d04
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3379
diff
changeset
|
549 |
return tileh; |
39 | 550 |
} |
551 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
552 |
static void GetAcceptedCargo_Clear(TileIndex tile, AcceptedCargo ac) |
0 | 553 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
554 |
/* unused */ |
0 | 555 |
} |
556 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
557 |
static void AnimateTile_Clear(TileIndex tile) |
0 | 558 |
{ |
559 |
/* unused */ |
|
560 |
} |
|
561 |
||
1293 | 562 |
void TileLoopClearHelper(TileIndex tile) |
0 | 563 |
{ |
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 |
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
|
565 |
byte neighbour; |
1293 | 566 |
TileIndex dirty = INVALID_TILE; |
0 | 567 |
|
3447 | 568 |
self = (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_FIELDS)); |
0 | 569 |
|
3447 | 570 |
neighbour = (IsTileType(TILE_ADDXY(tile, 1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 1, 0), CLEAR_FIELDS)); |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
571 |
if (GetFenceSW(tile) == 0) { |
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
572 |
if (self != neighbour) { |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
573 |
SetFenceSW(tile, 3); |
0 | 574 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
575 |
} |
0 | 576 |
} 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
|
577 |
if (self == 0 && neighbour == 0) { |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
578 |
SetFenceSW(tile, 0); |
0 | 579 |
dirty = tile; |
580 |
} |
|
581 |
} |
|
582 |
||
3447 | 583 |
neighbour = (IsTileType(TILE_ADDXY(tile, 0, 1), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 0, 1), CLEAR_FIELDS)); |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
584 |
if (GetFenceSE(tile) == 0) { |
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
585 |
if (self != neighbour) { |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
586 |
SetFenceSE(tile, 3); |
0 | 587 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
588 |
} |
0 | 589 |
} 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
|
590 |
if (self == 0 && neighbour == 0) { |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
591 |
SetFenceSE(tile, 0); |
0 | 592 |
dirty = tile; |
593 |
} |
|
594 |
} |
|
595 |
||
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 |
if (dirty != INVALID_TILE) MarkTileDirtyByTile(dirty); |
0 | 597 |
} |
598 |
||
599 |
||
600 |
/* convert into snowy tiles */ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
601 |
static void TileLoopClearAlps(TileIndex tile) |
0 | 602 |
{ |
4157
0c3210247472
(svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents:
4069
diff
changeset
|
603 |
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
|
604 |
|
4157
0c3210247472
(svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents:
4069
diff
changeset
|
605 |
if (k < 0) { // well below the snow line |
3447 | 606 |
if (!IsClearGround(tile, CLEAR_SNOW)) return; |
607 |
if (GetClearDensity(tile) == 0) SetClearGroundDensity(tile, CLEAR_GRASS, 3); |
|
0 | 608 |
} else { |
3447 | 609 |
if (!IsClearGround(tile, CLEAR_SNOW)) { |
610 |
SetClearGroundDensity(tile, CLEAR_SNOW, 0); |
|
2955
27221592ebbc
(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
|
611 |
} else { |
4157
0c3210247472
(svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents:
4069
diff
changeset
|
612 |
uint density = min((uint)k / TILE_HEIGHT, 3); |
2955
27221592ebbc
(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 |
|
27221592ebbc
(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 |
if (GetClearDensity(tile) < density) { |
27221592ebbc
(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 |
AddClearDensity(tile, 1); |
27221592ebbc
(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 |
} else if (GetClearDensity(tile) > density) { |
27221592ebbc
(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 |
AddClearDensity(tile, -1); |
27221592ebbc
(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 |
} else { |
27221592ebbc
(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 |
return; |
27221592ebbc
(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 |
} |
27221592ebbc
(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
|
621 |
} |
0 | 622 |
} |
623 |
||
624 |
MarkTileDirtyByTile(tile); |
|
625 |
} |
|
626 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
627 |
static void TileLoopClearDesert(TileIndex tile) |
0 | 628 |
{ |
3447 | 629 |
if (IsClearGround(tile, CLEAR_DESERT)) return; |
0 | 630 |
|
3379
ea8aa9e71328
(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
|
631 |
if (GetTropicZone(tile) == TROPICZONE_DESERT) { |
3447 | 632 |
SetClearGroundDensity(tile, CLEAR_DESERT, 3); |
0 | 633 |
} else { |
3379
ea8aa9e71328
(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 |
if (GetTropicZone(tile + TileDiffXY( 1, 0)) != TROPICZONE_DESERT && |
ea8aa9e71328
(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(-1, 0)) != TROPICZONE_DESERT && |
ea8aa9e71328
(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 && |
ea8aa9e71328
(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
|
637 |
GetTropicZone(tile + TileDiffXY( 0, -1)) != TROPICZONE_DESERT) |
1981 | 638 |
return; |
3447 | 639 |
SetClearGroundDensity(tile, CLEAR_DESERT, 1); |
0 | 640 |
} |
641 |
||
642 |
MarkTileDirtyByTile(tile); |
|
643 |
} |
|
644 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
645 |
static void TileLoop_Clear(TileIndex tile) |
0 | 646 |
{ |
647 |
TileLoopClearHelper(tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
648 |
|
2989 | 649 |
switch (_opt.landscape) { |
650 |
case LT_DESERT: TileLoopClearDesert(tile); break; |
|
651 |
case LT_HILLY: TileLoopClearAlps(tile); break; |
|
0 | 652 |
} |
653 |
||
2955
27221592ebbc
(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
|
654 |
switch (GetClearGround(tile)) { |
3447 | 655 |
case CLEAR_GRASS: |
2955
27221592ebbc
(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
|
656 |
if (GetClearDensity(tile) == 3) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
657 |
|
2955
27221592ebbc
(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 (_game_mode != GM_EDITOR) { |
27221592ebbc
(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 |
if (GetClearCounter(tile) < 7) { |
27221592ebbc
(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 |
AddClearCounter(tile, 1); |
27221592ebbc
(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 |
return; |
27221592ebbc
(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 |
} else { |
27221592ebbc
(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 |
SetClearCounter(tile, 0); |
27221592ebbc
(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 |
AddClearDensity(tile, 1); |
27221592ebbc
(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 |
} |
27221592ebbc
(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
|
666 |
} else { |
3447 | 667 |
SetClearGroundDensity(tile, GB(Random(), 0, 8) > 21 ? CLEAR_GRASS : CLEAR_ROUGH, 3); |
0 | 668 |
} |
2955
27221592ebbc
(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 |
break; |
27221592ebbc
(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
|
670 |
|
3447 | 671 |
case CLEAR_FIELDS: { |
2955
27221592ebbc
(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 |
uint field_type; |
27221592ebbc
(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 |
|
27221592ebbc
(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 |
if (_game_mode == GM_EDITOR) return; |
27221592ebbc
(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 |
|
27221592ebbc
(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 |
if (GetClearCounter(tile) < 7) { |
27221592ebbc
(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 |
AddClearCounter(tile, 1); |
27221592ebbc
(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 |
return; |
27221592ebbc
(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 |
} else { |
27221592ebbc
(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 |
SetClearCounter(tile, 0); |
27221592ebbc
(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 |
} |
27221592ebbc
(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
|
682 |
|
4333
2ff83c9c81fa
(svn r6032) -Fix: when a farm is gone, remove the fields when it is full grown and should be harvest (not before that)
truelight
parents:
4328
diff
changeset
|
683 |
if (GetIndustryIndexOfField(tile) == INVALID_INDUSTRY && GetFieldType(tile) >= 7) { |
4328
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4300
diff
changeset
|
684 |
/* This farmfield is no longer farmfield, so make it grass again */ |
4815
c2a54b213fde
(svn r6739) -Fix (r6001): Crash on removing farmland belonging to a farm. The search would loop
Darkvater
parents:
4560
diff
changeset
|
685 |
MakeClear(tile, CLEAR_GRASS, 2); |
4328
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4300
diff
changeset
|
686 |
} else { |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4300
diff
changeset
|
687 |
field_type = GetFieldType(tile); |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4300
diff
changeset
|
688 |
field_type = (field_type < 8) ? field_type + 1 : 0; |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4300
diff
changeset
|
689 |
SetFieldType(tile, field_type); |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4300
diff
changeset
|
690 |
} |
2955
27221592ebbc
(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
|
691 |
break; |
0 | 692 |
} |
2955
27221592ebbc
(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
|
693 |
|
27221592ebbc
(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
|
694 |
default: |
0 | 695 |
return; |
696 |
} |
|
697 |
||
698 |
MarkTileDirtyByTile(tile); |
|
699 |
} |
|
700 |
||
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
|
701 |
void GenerateClearTile(void) |
0 | 702 |
{ |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
703 |
uint i, gi; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
704 |
TileIndex tile; |
0 | 705 |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
706 |
/* add rough tiles */ |
2635 | 707 |
i = ScaleByMapSize(GB(Random(), 0, 10) + 0x400); |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
708 |
gi = ScaleByMapSize(GB(Random(), 0, 7) + 0x80); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
709 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
710 |
SetGeneratingWorldProgress(GWP_ROUGH_ROCKY, gi + i); |
0 | 711 |
do { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
712 |
IncreaseGeneratingWorldProgress(GWP_ROUGH_ROCKY); |
2051 | 713 |
tile = RandomTile(); |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
714 |
if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_DESERT)) SetClearGroundDensity(tile, CLEAR_ROUGH, 3); |
0 | 715 |
} while (--i); |
716 |
||
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
717 |
/* add rocky tiles */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
718 |
i = gi; |
0 | 719 |
do { |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
720 |
uint32 r = Random(); |
2051 | 721 |
tile = RandomTileSeed(r); |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
722 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
723 |
IncreaseGeneratingWorldProgress(GWP_ROUGH_ROCKY); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
724 |
if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_DESERT)) { |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
725 |
uint j = GB(r, 16, 4) + 5; |
2951 | 726 |
for (;;) { |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
727 |
TileIndex tile_new; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
728 |
|
3447 | 729 |
SetClearGroundDensity(tile, CLEAR_ROCKS, 3); |
0 | 730 |
do { |
731 |
if (--j == 0) goto get_out; |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4344
diff
changeset
|
732 |
tile_new = tile + TileOffsByDiagDir(GB(Random(), 0, 2)); |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
733 |
} while (!IsTileType(tile_new, MP_CLEAR) || IsClearGround(tile_new, CLEAR_DESERT)); |
0 | 734 |
tile = tile_new; |
735 |
} |
|
736 |
get_out:; |
|
737 |
} |
|
738 |
} while (--i); |
|
739 |
} |
|
740 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
741 |
static void ClickTile_Clear(TileIndex tile) |
0 | 742 |
{ |
743 |
/* not used */ |
|
744 |
} |
|
745 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
746 |
static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode) |
0 | 747 |
{ |
748 |
return 0; |
|
749 |
} |
|
750 |
||
2220 | 751 |
static const StringID _clear_land_str[] = { |
2955
27221592ebbc
(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
|
752 |
STR_080D_GRASS, |
0 | 753 |
STR_080B_ROUGH_LAND, |
754 |
STR_080A_ROCKS, |
|
755 |
STR_080E_FIELDS, |
|
756 |
STR_080F_SNOW_COVERED_LAND, |
|
2955
27221592ebbc
(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 |
STR_0810_DESERT |
0 | 758 |
}; |
759 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
760 |
static void GetTileDesc_Clear(TileIndex tile, TileDesc *td) |
0 | 761 |
{ |
3447 | 762 |
if (IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) == 0) { |
2955
27221592ebbc
(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
|
763 |
td->str = STR_080C_BARE_LAND; |
27221592ebbc
(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
|
764 |
} else { |
27221592ebbc
(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
|
765 |
td->str = _clear_land_str[GetClearGround(tile)]; |
27221592ebbc
(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
|
766 |
} |
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
|
767 |
td->owner = GetTileOwner(tile); |
0 | 768 |
} |
769 |
||
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
|
770 |
static void ChangeTileOwner_Clear(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 771 |
{ |
772 |
return; |
|
773 |
} |
|
774 |
||
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
|
775 |
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
|
776 |
{ |
3422
12cdb13ddb56
(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
|
777 |
_opt.snow_line = _patches.snow_line_height * TILE_HEIGHT; |
0 | 778 |
} |
779 |
||
780 |
const TileTypeProcs _tile_type_clear_procs = { |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4333
diff
changeset
|
781 |
DrawTile_Clear, /* draw_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4333
diff
changeset
|
782 |
GetSlopeZ_Clear, /* get_slope_z_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4333
diff
changeset
|
783 |
ClearTile_Clear, /* clear_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4333
diff
changeset
|
784 |
GetAcceptedCargo_Clear, /* get_accepted_cargo_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4333
diff
changeset
|
785 |
GetTileDesc_Clear, /* get_tile_desc_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4333
diff
changeset
|
786 |
GetTileTrackStatus_Clear, /* get_tile_track_status_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4333
diff
changeset
|
787 |
ClickTile_Clear, /* click_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4333
diff
changeset
|
788 |
AnimateTile_Clear, /* animate_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4333
diff
changeset
|
789 |
TileLoop_Clear, /* tile_loop_clear */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4333
diff
changeset
|
790 |
ChangeTileOwner_Clear, /* change_tile_owner_clear */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4333
diff
changeset
|
791 |
NULL, /* get_produced_cargo_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4333
diff
changeset
|
792 |
NULL, /* vehicle_enter_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4333
diff
changeset
|
793 |
GetSlopeTileh_Clear, /* get_slope_tileh_proc */ |
0 | 794 |
}; |