author | Darkvater |
Tue, 13 Jun 2006 14:04:12 +0000 | |
changeset 4018 | a1722af2ba0b |
parent 4000 | bab1ebc37da0 |
child 4031 | 1b38b85ef653 |
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" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
473
diff
changeset
|
6 |
#include "table/strings.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2154
diff
changeset
|
7 |
#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
|
8 |
#include "map.h" |
2154
63a6b880b4c0
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2153
diff
changeset
|
9 |
#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
|
10 |
#include "tile.h" |
0 | 11 |
#include "viewport.h" |
12 |
#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
|
13 |
#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
|
14 |
#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
|
15 |
#include "table/sprites.h" |
3310
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
16 |
#include "unmovable_map.h" |
0 | 17 |
|
18 |
typedef struct TerraformerHeightMod { |
|
19 |
TileIndex tile; |
|
20 |
byte height; |
|
21 |
} TerraformerHeightMod; |
|
22 |
||
23 |
typedef struct TerraformerState { |
|
24 |
int height[4]; |
|
25 |
uint32 flags; |
|
26 |
||
27 |
int direction; |
|
28 |
int modheight_count; |
|
29 |
int tile_table_count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
30 |
|
0 | 31 |
int32 cost; |
32 |
||
33 |
TileIndex *tile_table; |
|
34 |
TerraformerHeightMod *modheight; |
|
35 |
||
36 |
} TerraformerState; |
|
37 |
||
38 |
static int TerraformAllowTileProcess(TerraformerState *ts, TileIndex tile) |
|
39 |
{ |
|
40 |
TileIndex *t; |
|
41 |
int count; |
|
42 |
||
2639 | 43 |
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return -1; |
0 | 44 |
|
45 |
t = ts->tile_table; |
|
2639 | 46 |
for (count = ts->tile_table_count; count != 0; count--, t++) { |
47 |
if (*t == tile) return 0; |
|
0 | 48 |
} |
49 |
||
50 |
return 1; |
|
51 |
} |
|
52 |
||
53 |
static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile) |
|
54 |
{ |
|
55 |
TerraformerHeightMod *mod = ts->modheight; |
|
56 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
57 |
|
2639 | 58 |
for (count = ts->modheight_count; count != 0; count--, mod++) { |
59 |
if (mod->tile == tile) return mod->height; |
|
0 | 60 |
} |
61 |
||
1044
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
62 |
return TileHeight(tile); |
0 | 63 |
} |
64 |
||
65 |
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile) |
|
66 |
{ |
|
67 |
int count; |
|
68 |
TileIndex *t; |
|
69 |
||
70 |
count = ts->tile_table_count; |
|
71 |
||
2639 | 72 |
if (count >= 625) return; |
0 | 73 |
|
2952 | 74 |
for (t = ts->tile_table; count != 0; count--,t++) { |
2639 | 75 |
if (*t == tile) return; |
0 | 76 |
} |
77 |
||
78 |
ts->tile_table[ts->tile_table_count++] = tile; |
|
79 |
} |
|
80 |
||
81 |
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile) |
|
82 |
{ |
|
1981 | 83 |
TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1)); |
84 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1)); |
|
85 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0)); |
|
0 | 86 |
TerraformAddDirtyTile(ts, tile); |
87 |
} |
|
88 |
||
4018
a1722af2ba0b
(svn r5248) - [Codechange]: Remove TerraformProc()'s mode parameter as it is not used
Darkvater
parents:
4000
diff
changeset
|
89 |
static int TerraformProc(TerraformerState *ts, TileIndex tile) |
0 | 90 |
{ |
91 |
int r; |
|
92 |
||
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
93 |
assert(tile < MapSize()); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
94 |
|
4018
a1722af2ba0b
(svn r5248) - [Codechange]: Remove TerraformProc()'s mode parameter as it is not used
Darkvater
parents:
4000
diff
changeset
|
95 |
if ((r = TerraformAllowTileProcess(ts, tile)) <= 0) return r; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
96 |
|
3279
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
97 |
if (!IsTileType(tile, MP_RAILWAY)) { |
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
|
98 |
int32 ret = DoCommand(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 99 |
|
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
|
100 |
if (CmdFailed(ret)) { |
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
101 |
_terraform_err_tile = tile; |
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
102 |
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
|
103 |
} |
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
|
104 |
|
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
|
105 |
ts->cost += ret; |
0 | 106 |
} |
107 |
||
2639 | 108 |
if (ts->tile_table_count >= 625) return -1; |
0 | 109 |
ts->tile_table[ts->tile_table_count++] = tile; |
110 |
||
111 |
return 0; |
|
112 |
} |
|
113 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
114 |
static bool TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height) |
0 | 115 |
{ |
116 |
int nh; |
|
117 |
TerraformerHeightMod *mod; |
|
118 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
119 |
|
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
120 |
assert(tile < MapSize()); |
0 | 121 |
|
122 |
if (height < 0) { |
|
123 |
_error_message = STR_1003_ALREADY_AT_SEA_LEVEL; |
|
124 |
return false; |
|
125 |
} |
|
126 |
||
127 |
_error_message = STR_1004_TOO_HIGH; |
|
128 |
||
2639 | 129 |
if (height > 15) return false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
130 |
|
0 | 131 |
nh = TerraformGetHeightOfTile(ts, tile); |
2639 | 132 |
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
|
133 |
|
4018
a1722af2ba0b
(svn r5248) - [Codechange]: Remove TerraformProc()'s mode parameter as it is not used
Darkvater
parents:
4000
diff
changeset
|
134 |
if (TerraformProc(ts, tile) < 0) return false; |
a1722af2ba0b
(svn r5248) - [Codechange]: Remove TerraformProc()'s mode parameter as it is not used
Darkvater
parents:
4000
diff
changeset
|
135 |
if (TerraformProc(ts, tile + TileDiffXY( 0, -1)) < 0) return false; |
a1722af2ba0b
(svn r5248) - [Codechange]: Remove TerraformProc()'s mode parameter as it is not used
Darkvater
parents:
4000
diff
changeset
|
136 |
if (TerraformProc(ts, tile + TileDiffXY(-1, -1)) < 0) return false; |
a1722af2ba0b
(svn r5248) - [Codechange]: Remove TerraformProc()'s mode parameter as it is not used
Darkvater
parents:
4000
diff
changeset
|
137 |
if (TerraformProc(ts, tile + TileDiffXY(-1, 0)) < 0) return false; |
0 | 138 |
|
139 |
mod = ts->modheight; |
|
140 |
count = ts->modheight_count; |
|
141 |
||
2639 | 142 |
for (;;) { |
0 | 143 |
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
|
144 |
if (ts->modheight_count >= 576) return false; |
0 | 145 |
ts->modheight_count++; |
146 |
break; |
|
147 |
} |
|
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
148 |
if (mod->tile == tile) break; |
0 | 149 |
mod++; |
150 |
count--; |
|
151 |
} |
|
152 |
||
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
153 |
mod->tile = tile; |
0 | 154 |
mod->height = (byte)height; |
155 |
||
156 |
ts->cost += _price.terraform; |
|
157 |
||
158 |
{ |
|
159 |
int direction = ts->direction, r; |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
160 |
const TileIndexDiffC *ttm; |
0 | 161 |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
162 |
static const TileIndexDiffC _terraform_tilepos[] = { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
163 |
{ 1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
164 |
{-2, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
165 |
{ 1, 1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
166 |
{ 0, -2} |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
167 |
}; |
0 | 168 |
|
2952 | 169 |
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
|
170 |
tile += ToTileIndexDiff(*ttm); |
0 | 171 |
|
172 |
r = TerraformGetHeightOfTile(ts, tile); |
|
173 |
if (r != height && r-direction != height && r+direction != height) { |
|
174 |
if (!TerraformTileHeight(ts, tile, r+direction)) |
|
175 |
return false; |
|
176 |
} |
|
177 |
} |
|
178 |
} |
|
179 |
||
180 |
return true; |
|
181 |
} |
|
182 |
||
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
|
183 |
/** 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
|
184 |
* @param tile tile to terraform |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
185 |
* @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
|
186 |
* @param p2 direction; eg up or down |
0 | 187 |
*/ |
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
|
188 |
int32 CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 189 |
{ |
190 |
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
|
191 |
TileIndex t; |
0 | 192 |
int direction; |
193 |
||
194 |
TerraformerHeightMod modheight_data[576]; |
|
195 |
TileIndex tile_table_data[625]; |
|
196 |
||
197 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
198 |
||
199 |
_terraform_err_tile = 0; |
|
200 |
||
201 |
ts.direction = direction = p2 ? 1 : -1; |
|
202 |
ts.flags = flags; |
|
203 |
ts.modheight_count = ts.tile_table_count = 0; |
|
204 |
ts.cost = 0; |
|
205 |
ts.modheight = modheight_data; |
|
206 |
ts.tile_table = tile_table_data; |
|
207 |
||
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
|
208 |
/* 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
|
209 |
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
|
210 |
|
0 | 211 |
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
|
212 |
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
|
213 |
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
|
214 |
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
|
215 |
} |
0 | 216 |
} |
217 |
||
218 |
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
|
219 |
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
|
220 |
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
|
221 |
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
|
222 |
} |
0 | 223 |
} |
224 |
||
225 |
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
|
226 |
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
|
227 |
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
|
228 |
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
|
229 |
} |
0 | 230 |
} |
231 |
||
232 |
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
|
233 |
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
|
234 |
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
|
235 |
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
|
236 |
} |
0 | 237 |
} |
238 |
||
3279
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
239 |
{ /* Check if tunnel or track would take damage */ |
0 | 240 |
int count; |
241 |
TileIndex *ti = ts.tile_table; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
242 |
|
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
|
243 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
3279
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
244 |
uint a, b, c, d, r, min; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
245 |
TileIndex tile = *ti; |
0 | 246 |
|
3279
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
247 |
_terraform_err_tile = tile; |
0 | 248 |
|
3279
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
249 |
a = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); |
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
250 |
b = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); |
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
251 |
c = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); |
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
252 |
d = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); |
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
253 |
|
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
254 |
r = GetTileh(a, b, c, d, &min); |
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
255 |
|
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
256 |
if (IsTileType(tile, MP_RAILWAY)) { |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
257 |
if (IsSteepSlope(r)) return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
3279
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
258 |
|
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
259 |
if (IsPlainRailTile(tile)) { |
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
260 |
extern const TrackBits _valid_tileh_slopes[2][15]; |
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
261 |
if (GetTrackBits(tile) & ~_valid_tileh_slopes[0][r]) return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
262 |
} else return_cmd_error(STR_5800_OBJECT_IN_THE_WAY); |
2639 | 263 |
} |
3279
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
264 |
|
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
265 |
if (direction == -1 && IsTunnelInWay(tile, min)) return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); |
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
266 |
|
7c642c5c501c
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
267 |
_terraform_err_tile = 0; |
0 | 268 |
} |
269 |
} |
|
270 |
||
271 |
if (flags & DC_EXEC) { |
|
272 |
/* Clear the landscape at the tiles */ |
|
273 |
{ |
|
274 |
int count; |
|
275 |
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
|
276 |
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
|
277 |
DoCommand(*ti, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
0 | 278 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
279 |
} |
0 | 280 |
|
281 |
/* change the height */ |
|
282 |
{ |
|
283 |
int count; |
|
284 |
TerraformerHeightMod *mod; |
|
285 |
||
286 |
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
|
287 |
for (count = ts.modheight_count; count != 0; count--, mod++) { |
1979
f4462d4e8e62
(svn r2485) Missed two uint -> TileIndex, thanks _Luca_
tron
parents:
1977
diff
changeset
|
288 |
TileIndex til = mod->tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
289 |
|
1059
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
290 |
SetTileHeight(til, mod->height); |
0 | 291 |
TerraformAddDirtyTileAround(&ts, til); |
292 |
} |
|
293 |
} |
|
294 |
||
295 |
/* finally mark the dirty tiles dirty */ |
|
296 |
{ |
|
297 |
int count; |
|
298 |
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
|
299 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 300 |
MarkTileDirtyByTile(*ti); |
301 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
302 |
} |
0 | 303 |
} |
304 |
return ts.cost; |
|
305 |
} |
|
306 |
||
307 |
||
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
|
308 |
/** 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
|
309 |
* @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
|
310 |
* @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
|
311 |
* @param p2 unused |
0 | 312 |
*/ |
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
|
313 |
int32 CmdLevelLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 314 |
{ |
315 |
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
|
316 |
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
|
317 |
int ey; |
0 | 318 |
int sx, sy; |
319 |
uint h, curh; |
|
320 |
int32 ret, cost, money; |
|
321 |
||
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
|
322 |
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
|
323 |
|
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
|
324 |
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
|
325 |
|
0 | 326 |
// remember level height |
1044
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
327 |
h = TileHeight(p1); |
0 | 328 |
|
329 |
// 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
|
330 |
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
|
331 |
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
|
332 |
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
|
333 |
sy = TileY(p1); |
0 | 334 |
if (ex < sx) intswap(ex, sx); |
335 |
if (ey < sy) intswap(ey, sy); |
|
1981 | 336 |
tile = TileXY(sx, sy); |
0 | 337 |
|
338 |
size_x = ex-sx+1; |
|
339 |
size_y = ey-sy+1; |
|
340 |
||
341 |
money = GetAvailableMoneyForCommand(); |
|
342 |
cost = 0; |
|
343 |
||
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
344 |
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
|
345 |
curh = TileHeight(tile2); |
0 | 346 |
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
|
347 |
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
|
348 |
if (CmdFailed(ret)) break; |
0 | 349 |
cost += ret; |
350 |
||
351 |
if (flags & DC_EXEC) { |
|
352 |
if ((money -= ret) < 0) { |
|
353 |
_additional_cash_required = ret; |
|
354 |
return cost - ret; |
|
355 |
} |
|
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
|
356 |
DoCommand(tile2, 8, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND); |
0 | 357 |
} |
358 |
||
359 |
curh += (curh > h) ? -1 : 1; |
|
360 |
} |
|
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
|
361 |
} END_TILE_LOOP(tile2, size_x, size_y, tile) |
0 | 362 |
|
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
|
363 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 364 |
} |
365 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
366 |
/** 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
|
367 |
* 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
|
368 |
* @param tile the tile the player is purchasing |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
369 |
* @param p1 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
370 |
* @param p2 unused |
0 | 371 |
*/ |
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
|
372 |
int32 CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 373 |
{ |
374 |
int32 cost; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
375 |
|
0 | 376 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
377 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
378 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 379 |
|
3310
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
380 |
if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_player)) { |
0 | 381 |
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
|
382 |
} |
0 | 383 |
|
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
|
384 |
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
|
385 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 386 |
|
387 |
if (flags & DC_EXEC) { |
|
3310
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
388 |
MakeOwnedLand(tile, _current_player); |
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
389 |
MarkTileDirtyByTile(tile); |
0 | 390 |
} |
391 |
||
392 |
return cost + _price.purchase_land * 10; |
|
393 |
} |
|
394 |
||
395 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
396 |
static int32 ClearTile_Clear(TileIndex tile, byte flags) |
1095 | 397 |
{ |
2220 | 398 |
static const int32* clear_price_table[] = { |
399 |
&_price.clear_1, |
|
400 |
&_price.purchase_land, |
|
401 |
&_price.clear_2, |
|
402 |
&_price.clear_3, |
|
403 |
&_price.purchase_land, |
|
404 |
&_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
|
405 |
&_price.clear_2, // XXX unused? |
0 | 406 |
}; |
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
|
407 |
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
|
408 |
|
3447 | 409 |
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
|
410 |
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
|
411 |
} 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
|
412 |
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
|
413 |
} |
0 | 414 |
|
2220 | 415 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 416 |
|
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
|
417 |
return price; |
0 | 418 |
} |
419 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
420 |
/** 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
|
421 |
* 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
|
422 |
* @param tile the tile the player is selling |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
423 |
* @param p1 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
424 |
* @param p2 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
425 |
*/ |
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
|
426 |
int32 CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 427 |
{ |
428 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
429 |
||
3310
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
430 |
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
|
431 |
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
|
432 |
|
0 | 433 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
434 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 435 |
|
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
|
436 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 437 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
438 |
return - _price.purchase_land * 2; |
0 | 439 |
} |
440 |
||
441 |
||
442 |
#include "table/clear_land.h" |
|
443 |
||
444 |
||
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
|
445 |
void DrawClearLandTile(const TileInfo *ti, byte set) |
0 | 446 |
{ |
2517
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
447 |
DrawGroundSprite(SPR_FLAT_BARE_LAND + _tileh_to_sprite[ti->tileh] + set * 19); |
0 | 448 |
} |
449 |
||
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
|
450 |
void DrawHillyLandTile(const TileInfo *ti) |
0 | 451 |
{ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
452 |
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
|
453 |
DrawGroundSprite(SPR_FLAT_ROUGH_LAND + _tileh_to_sprite[ti->tileh]); |
0 | 454 |
} 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
|
455 |
DrawGroundSprite(_landscape_clear_sprites[GB(ti->x ^ ti->y, 4, 3)]); |
0 | 456 |
} |
457 |
} |
|
458 |
||
2220 | 459 |
void DrawClearLandFence(const TileInfo *ti) |
0 | 460 |
{ |
461 |
byte z = ti->z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
462 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
463 |
if (ti->tileh & SLOPE_S) { |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
464 |
z += TILE_HEIGHT; |
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
465 |
if (ti->tileh == SLOPE_STEEP_S) z += TILE_HEIGHT; |
0 | 466 |
} |
467 |
||
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
468 |
if (GetFenceSW(ti->tile) != 0) { |
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
469 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSW(ti->tile) - 1] + _fence_mod_by_tileh[ti->tileh], ti->x, ti->y, z); |
0 | 470 |
} |
471 |
||
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
472 |
if (GetFenceSE(ti->tile) != 0) { |
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
473 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSE(ti->tile) - 1] + _fence_mod_by_tileh_2[ti->tileh], ti->x, ti->y, z); |
0 | 474 |
} |
475 |
} |
|
476 |
||
477 |
static void DrawTile_Clear(TileInfo *ti) |
|
478 |
{ |
|
3166
747e74d236f0
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
479 |
switch (GetClearGround(ti->tile)) { |
3447 | 480 |
case CLEAR_GRASS: |
3166
747e74d236f0
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
481 |
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
|
482 |
break; |
0 | 483 |
|
3447 | 484 |
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
|
485 |
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
|
486 |
break; |
0 | 487 |
|
3447 | 488 |
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
|
489 |
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
|
490 |
break; |
0 | 491 |
|
3447 | 492 |
case CLEAR_FIELDS: |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
493 |
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
|
494 |
break; |
0 | 495 |
|
3447 | 496 |
case CLEAR_SNOW: |
3166
747e74d236f0
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
497 |
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
|
498 |
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
|
499 |
|
3447 | 500 |
case CLEAR_DESERT: |
3166
747e74d236f0
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
501 |
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
|
502 |
break; |
0 | 503 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
504 |
|
2220 | 505 |
DrawClearLandFence(ti); |
0 | 506 |
} |
507 |
||
2537 | 508 |
static uint GetSlopeZ_Clear(const TileInfo* ti) |
1095 | 509 |
{ |
510 |
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z; |
|
511 |
} |
|
0 | 512 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
513 |
static Slope GetSlopeTileh_Clear(TileIndex tile, Slope tileh) |
39 | 514 |
{ |
3418
a592d40a4d04
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3379
diff
changeset
|
515 |
return tileh; |
39 | 516 |
} |
517 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
518 |
static void GetAcceptedCargo_Clear(TileIndex tile, AcceptedCargo ac) |
0 | 519 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
520 |
/* unused */ |
0 | 521 |
} |
522 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
523 |
static void AnimateTile_Clear(TileIndex tile) |
0 | 524 |
{ |
525 |
/* unused */ |
|
526 |
} |
|
527 |
||
1293 | 528 |
void TileLoopClearHelper(TileIndex tile) |
0 | 529 |
{ |
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
530 |
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
|
531 |
byte neighbour; |
1293 | 532 |
TileIndex dirty = INVALID_TILE; |
0 | 533 |
|
3447 | 534 |
self = (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_FIELDS)); |
0 | 535 |
|
3447 | 536 |
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
|
537 |
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
|
538 |
if (self != neighbour) { |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
539 |
SetFenceSW(tile, 3); |
0 | 540 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
541 |
} |
0 | 542 |
} 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
|
543 |
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
|
544 |
SetFenceSW(tile, 0); |
0 | 545 |
dirty = tile; |
546 |
} |
|
547 |
} |
|
548 |
||
3447 | 549 |
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
|
550 |
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
|
551 |
if (self != neighbour) { |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
552 |
SetFenceSE(tile, 3); |
0 | 553 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
554 |
} |
0 | 555 |
} 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
|
556 |
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
|
557 |
SetFenceSE(tile, 0); |
0 | 558 |
dirty = tile; |
559 |
} |
|
560 |
} |
|
561 |
||
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
562 |
if (dirty != INVALID_TILE) MarkTileDirtyByTile(dirty); |
0 | 563 |
} |
564 |
||
565 |
||
566 |
/* convert into snowy tiles */ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
567 |
static void TileLoopClearAlps(TileIndex tile) |
0 | 568 |
{ |
569 |
/* distance from snow line, in steps of 8 */ |
|
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
|
570 |
int k = GetTileZ(tile) - _opt.snow_line; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
571 |
|
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
|
572 |
if (k < -TILE_HEIGHT) { // well below the snow line |
3447 | 573 |
if (!IsClearGround(tile, CLEAR_SNOW)) return; |
574 |
if (GetClearDensity(tile) == 0) SetClearGroundDensity(tile, CLEAR_GRASS, 3); |
|
0 | 575 |
} else { |
3447 | 576 |
if (!IsClearGround(tile, CLEAR_SNOW)) { |
577 |
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
|
578 |
} else { |
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
|
579 |
uint density = min((uint)(k + TILE_HEIGHT) / 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
|
580 |
|
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
|
581 |
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
|
582 |
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
|
583 |
} 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
|
584 |
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
|
585 |
} 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
|
586 |
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
|
587 |
} |
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
|
588 |
} |
0 | 589 |
} |
590 |
||
591 |
MarkTileDirtyByTile(tile); |
|
592 |
} |
|
593 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
594 |
static void TileLoopClearDesert(TileIndex tile) |
0 | 595 |
{ |
3447 | 596 |
if (IsClearGround(tile, CLEAR_DESERT)) return; |
0 | 597 |
|
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
|
598 |
if (GetTropicZone(tile) == TROPICZONE_DESERT) { |
3447 | 599 |
SetClearGroundDensity(tile, CLEAR_DESERT, 3); |
0 | 600 |
} 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
|
601 |
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
|
602 |
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
|
603 |
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
|
604 |
GetTropicZone(tile + TileDiffXY( 0, -1)) != TROPICZONE_DESERT) |
1981 | 605 |
return; |
3447 | 606 |
SetClearGroundDensity(tile, CLEAR_DESERT, 1); |
0 | 607 |
} |
608 |
||
609 |
MarkTileDirtyByTile(tile); |
|
610 |
} |
|
611 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
612 |
static void TileLoop_Clear(TileIndex tile) |
0 | 613 |
{ |
614 |
TileLoopClearHelper(tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
615 |
|
2989 | 616 |
switch (_opt.landscape) { |
617 |
case LT_DESERT: TileLoopClearDesert(tile); break; |
|
618 |
case LT_HILLY: TileLoopClearAlps(tile); break; |
|
0 | 619 |
} |
620 |
||
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
|
621 |
switch (GetClearGround(tile)) { |
3447 | 622 |
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
|
623 |
if (GetClearDensity(tile) == 3) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
624 |
|
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
|
625 |
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
|
626 |
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
|
627 |
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
|
628 |
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
|
629 |
} 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
|
630 |
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
|
631 |
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
|
632 |
} |
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
|
633 |
} else { |
3447 | 634 |
SetClearGroundDensity(tile, GB(Random(), 0, 8) > 21 ? CLEAR_GRASS : CLEAR_ROUGH, 3); |
0 | 635 |
} |
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
|
636 |
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
|
637 |
|
3447 | 638 |
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
|
639 |
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
|
640 |
|
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
|
641 |
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
|
642 |
|
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
|
643 |
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
|
644 |
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
|
645 |
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
|
646 |
} 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
|
647 |
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
|
648 |
} |
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
|
649 |
|
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
650 |
field_type = GetFieldType(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
|
651 |
field_type = (field_type < 8) ? field_type + 1 : 0; |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
652 |
SetFieldType(tile, field_type); |
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
|
653 |
break; |
0 | 654 |
} |
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
|
655 |
|
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 |
default: |
0 | 657 |
return; |
658 |
} |
|
659 |
||
660 |
MarkTileDirtyByTile(tile); |
|
661 |
} |
|
662 |
||
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
|
663 |
void GenerateClearTile(void) |
0 | 664 |
{ |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
665 |
uint i; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
666 |
TileIndex tile; |
0 | 667 |
|
668 |
/* add hills */ |
|
2635 | 669 |
i = ScaleByMapSize(GB(Random(), 0, 10) + 0x400); |
0 | 670 |
do { |
2051 | 671 |
tile = RandomTile(); |
3447 | 672 |
if (IsTileType(tile, MP_CLEAR)) SetClearGroundDensity(tile, CLEAR_ROUGH, 3); |
0 | 673 |
} while (--i); |
674 |
||
675 |
/* add grey squares */ |
|
2635 | 676 |
i = ScaleByMapSize(GB(Random(), 0, 7) + 0x80); |
0 | 677 |
do { |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
678 |
uint32 r = Random(); |
2051 | 679 |
tile = RandomTileSeed(r); |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
926
diff
changeset
|
680 |
if (IsTileType(tile, MP_CLEAR)) { |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
681 |
uint j = GB(r, 16, 4) + 5; |
2951 | 682 |
for (;;) { |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
683 |
TileIndex tile_new; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
684 |
|
3447 | 685 |
SetClearGroundDensity(tile, CLEAR_ROCKS, 3); |
0 | 686 |
do { |
687 |
if (--j == 0) goto get_out; |
|
2635 | 688 |
tile_new = tile + TileOffsByDir(GB(Random(), 0, 2)); |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
926
diff
changeset
|
689 |
} while (!IsTileType(tile_new, MP_CLEAR)); |
0 | 690 |
tile = tile_new; |
691 |
} |
|
692 |
get_out:; |
|
693 |
} |
|
694 |
} while (--i); |
|
695 |
} |
|
696 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
697 |
static void ClickTile_Clear(TileIndex tile) |
0 | 698 |
{ |
699 |
/* not used */ |
|
700 |
} |
|
701 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
702 |
static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode) |
0 | 703 |
{ |
704 |
return 0; |
|
705 |
} |
|
706 |
||
2220 | 707 |
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
|
708 |
STR_080D_GRASS, |
0 | 709 |
STR_080B_ROUGH_LAND, |
710 |
STR_080A_ROCKS, |
|
711 |
STR_080E_FIELDS, |
|
712 |
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
|
713 |
STR_0810_DESERT |
0 | 714 |
}; |
715 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
716 |
static void GetTileDesc_Clear(TileIndex tile, TileDesc *td) |
0 | 717 |
{ |
3447 | 718 |
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
|
719 |
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
|
720 |
} 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
|
721 |
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
|
722 |
} |
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
|
723 |
td->owner = GetTileOwner(tile); |
0 | 724 |
} |
725 |
||
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
|
726 |
static void ChangeTileOwner_Clear(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 727 |
{ |
728 |
return; |
|
729 |
} |
|
730 |
||
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
|
731 |
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
|
732 |
{ |
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
|
733 |
_opt.snow_line = _patches.snow_line_height * TILE_HEIGHT; |
0 | 734 |
} |
735 |
||
736 |
const TileTypeProcs _tile_type_clear_procs = { |
|
737 |
DrawTile_Clear, /* draw_tile_proc */ |
|
738 |
GetSlopeZ_Clear, /* get_slope_z_proc */ |
|
739 |
ClearTile_Clear, /* clear_tile_proc */ |
|
740 |
GetAcceptedCargo_Clear, /* get_accepted_cargo_proc */ |
|
741 |
GetTileDesc_Clear, /* get_tile_desc_proc */ |
|
742 |
GetTileTrackStatus_Clear, /* get_tile_track_status_proc */ |
|
743 |
ClickTile_Clear, /* click_tile_proc */ |
|
744 |
AnimateTile_Clear, /* animate_tile_proc */ |
|
745 |
TileLoop_Clear, /* tile_loop_clear */ |
|
746 |
ChangeTileOwner_Clear, /* change_tile_owner_clear */ |
|
747 |
NULL, /* get_produced_cargo_proc */ |
|
748 |
NULL, /* vehicle_enter_tile_proc */ |
|
39 | 749 |
GetSlopeTileh_Clear, /* get_slope_tileh_proc */ |
0 | 750 |
}; |