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