author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1399 | 61e7c68e9da6 |
child 1605 | 279dd2265cae |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
1363
775a7ee52369
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1359
diff
changeset
|
3 |
#include "table/sprites.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
4 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
588
diff
changeset
|
5 |
#include "map.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:
1132
diff
changeset
|
6 |
#include "tile.h" |
0 | 7 |
#include "vehicle.h" |
8 |
#include "viewport.h" |
|
9 |
#include "command.h" |
|
10 |
#include "town.h" |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
11 |
#include "news.h" |
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
314
diff
changeset
|
12 |
#include "sound.h" |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
13 |
#include "depot.h" |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
14 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
15 |
static void FloodVehicle(Vehicle *v); |
0 | 16 |
|
410 | 17 |
static bool IsClearWaterTile(uint tile) |
0 | 18 |
{ |
19 |
TileInfo ti; |
|
20 |
FindLandscapeHeightByTile(&ti, tile); |
|
21 |
return (ti.type == MP_WATER && ti.tileh == 0 && ti.map5 == 0); |
|
22 |
} |
|
23 |
||
24 |
/* Build a ship depot |
|
25 |
* p1 - direction |
|
26 |
*/ |
|
27 |
||
28 |
int32 CmdBuildShipDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
29 |
{ |
|
30 |
uint tile, tile2; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
31 |
|
0 | 32 |
int32 cost, ret; |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
33 |
Depot *depot; |
0 | 34 |
|
35 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
36 |
||
37 |
tile = TILE_FROM_XY(x,y); |
|
38 |
if (!EnsureNoVehicle(tile)) |
|
39 |
return CMD_ERROR; |
|
40 |
||
41 |
tile2 = tile + (p1 ? TILE_XY(0,1) : TILE_XY(1,0)); |
|
42 |
if (!EnsureNoVehicle(tile2)) |
|
43 |
return CMD_ERROR; |
|
44 |
||
45 |
if (!IsClearWaterTile(tile) || !IsClearWaterTile(tile2)) |
|
46 |
return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER); |
|
47 |
||
48 |
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
49 |
if (ret == CMD_ERROR) return CMD_ERROR; |
|
50 |
ret = DoCommandByTile(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
51 |
if (ret == CMD_ERROR) |
|
52 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
53 |
|
0 | 54 |
// pretend that we're not making land from the water even though we actually are. |
55 |
cost = 0; |
|
56 |
||
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
57 |
depot = AllocateDepot(); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
58 |
if (depot == NULL) |
0 | 59 |
return CMD_ERROR; |
60 |
||
61 |
if (flags & DC_EXEC) { |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
62 |
depot->xy = tile; |
0 | 63 |
_last_built_ship_depot_tile = tile; |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
64 |
depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
0 | 65 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
66 |
ModifyTile(tile, |
0 | 67 |
MP_SETTYPE(MP_WATER) | MP_MAPOWNER_CURRENT | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, |
68 |
(0x80 + p1*2) |
|
69 |
); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
70 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
71 |
ModifyTile(tile2, |
0 | 72 |
MP_SETTYPE(MP_WATER) | MP_MAPOWNER_CURRENT | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, |
73 |
(0x81 + p1*2) |
|
74 |
); |
|
75 |
} |
|
76 |
||
77 |
return cost + _price.build_ship_depot; |
|
78 |
} |
|
79 |
||
80 |
static int32 RemoveShipDepot(uint tile, uint32 flags) |
|
81 |
{ |
|
82 |
uint tile2; |
|
83 |
||
84 |
if (!CheckTileOwnership(tile)) |
|
85 |
return CMD_ERROR; |
|
86 |
||
87 |
if (!EnsureNoVehicle(tile)) |
|
88 |
return CMD_ERROR; |
|
89 |
||
90 |
tile2 = tile + ((_map5[tile] & 2) ? TILE_XY(0,1) : TILE_XY(1,0)); |
|
91 |
||
92 |
if (!EnsureNoVehicle(tile2)) |
|
93 |
return CMD_ERROR; |
|
94 |
||
95 |
if (flags & DC_EXEC) { |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
96 |
/* Kill the depot */ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
97 |
DoDeleteDepot(tile); |
0 | 98 |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
99 |
/* Make the tiles water */ |
0 | 100 |
ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0); |
101 |
ModifyTile(tile2, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0); |
|
102 |
} |
|
103 |
||
104 |
return _price.remove_ship_depot; |
|
105 |
} |
|
106 |
||
107 |
// build a shiplift |
|
108 |
static int32 DoBuildShiplift(uint tile, int dir, uint32 flags) |
|
109 |
{ |
|
110 |
int32 ret; |
|
111 |
int delta; |
|
112 |
||
113 |
// middle tile |
|
114 |
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
115 |
if (ret == CMD_ERROR) return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
116 |
|
900 | 117 |
delta = TileOffsByDir(dir); |
0 | 118 |
// lower tile |
119 |
ret = DoCommandByTile(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
120 |
if (ret == CMD_ERROR) return CMD_ERROR; |
|
121 |
if (GetTileSlope(tile - delta, NULL)) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
122 |
||
123 |
// upper tile |
|
124 |
ret = DoCommandByTile(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
125 |
if (ret == CMD_ERROR) return CMD_ERROR; |
|
126 |
if (GetTileSlope(tile + delta, NULL)) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
127 |
||
128 |
if (flags & DC_EXEC) { |
|
129 |
ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0x10 + dir); |
|
130 |
ModifyTile(tile - delta, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0x14 + dir); |
|
131 |
ModifyTile(tile + delta, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0x18 + dir); |
|
132 |
} |
|
133 |
||
134 |
return _price.clear_water * 22 >> 3; |
|
135 |
} |
|
136 |
||
137 |
static int32 RemoveShiplift(uint tile, uint32 flags) |
|
138 |
{ |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
139 |
TileIndexDiff delta = TileOffsByDir(_map5[tile] & 3); |
0 | 140 |
|
141 |
// make sure no vehicle is on the tile. |
|
142 |
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(tile + delta) || !EnsureNoVehicle(tile - delta)) |
|
143 |
return CMD_ERROR; |
|
144 |
||
145 |
if (flags & DC_EXEC) { |
|
146 |
DoClearSquare(tile); |
|
147 |
DoClearSquare(tile + delta); |
|
148 |
DoClearSquare(tile - delta); |
|
149 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
150 |
|
0 | 151 |
return _price.clear_water * 2; |
152 |
} |
|
153 |
||
154 |
static void MarkTilesAroundDirty(uint tile) |
|
155 |
{ |
|
156 |
MarkTileDirtyByTile(TILE_ADDXY(tile, 0, 1)); |
|
157 |
MarkTileDirtyByTile(TILE_ADDXY(tile, 0, -1)); |
|
158 |
MarkTileDirtyByTile(TILE_ADDXY(tile, 1, 0)); |
|
159 |
MarkTileDirtyByTile(TILE_ADDXY(tile, -1, 0)); |
|
160 |
} |
|
161 |
||
162 |
int32 CmdBuildLock(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
163 |
{ |
|
164 |
uint tile = TILE_FROM_XY(x,y); |
|
165 |
int32 ret; |
|
166 |
uint th; |
|
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
|
167 |
|
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
|
168 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
169 |
th = GetTileSlope(tile, NULL); |
0 | 170 |
|
171 |
if (th==3 || th==6 || th==9 || th==12) { |
|
172 |
static const byte _shiplift_dirs[16] = {0,0,0,2,0,0,1,0,0,3,0,0,0}; |
|
173 |
ret = DoBuildShiplift(tile, _shiplift_dirs[th], flags); |
|
174 |
return ret; |
|
175 |
} |
|
176 |
else |
|
177 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
178 |
} |
|
179 |
||
180 |
int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
181 |
{ |
|
182 |
uint tile = TILE_FROM_XY(x,y); |
|
183 |
int32 ret; |
|
184 |
uint th; |
|
185 |
uint endtile = (uint)p1; |
|
186 |
int delta; |
|
187 |
int32 cost; |
|
188 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
189 |
||
190 |
// move in which direction? |
|
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
|
191 |
delta = (TileX(tile) == TileX(endtile)) ? TILE_XY(0,1) : TILE_XY(1,0); |
0 | 192 |
if (endtile < tile) delta = -delta; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
193 |
|
0 | 194 |
cost = 0; |
195 |
for(;;) { |
|
196 |
ret = 0; |
|
197 |
th = GetTileSlope(tile, NULL); |
|
198 |
if(th!=0) |
|
726
ee8f435f229b
(svn r1178) Fix: Error message for building canals on slopes is correct
dominik
parents:
714
diff
changeset
|
199 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
0 | 200 |
|
201 |
// can't make water of water! |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1008
diff
changeset
|
202 |
if (IsTileType(tile, MP_WATER)) { |
0 | 203 |
_error_message = STR_1007_ALREADY_BUILT; |
204 |
} else { |
|
205 |
||
206 |
/* is middle piece of a bridge? */ |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1008
diff
changeset
|
207 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && _map5[tile] & 0x40) { /* build under bridge */ |
0 | 208 |
if(_map5[tile] & 0x20) { // transport route under bridge |
209 |
_error_message = STR_5800_OBJECT_IN_THE_WAY; |
|
210 |
ret = CMD_ERROR; |
|
211 |
} |
|
212 |
else if (_map5[tile] & 0x18) { // already water under bridge |
|
213 |
_error_message = STR_1007_ALREADY_BUILT; |
|
214 |
ret = CMD_ERROR; |
|
215 |
} |
|
216 |
||
217 |
/* no bridge? then try to clear it. */ |
|
218 |
} else { |
|
219 |
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
220 |
} |
|
221 |
if (ret == CMD_ERROR) return ret; |
|
222 |
cost += ret; |
|
223 |
||
224 |
/* execute modifications */ |
|
225 |
if (flags & DC_EXEC) { |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1008
diff
changeset
|
226 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
0 | 227 |
// change owner to OWNER_WATER and set land under bridge bit to water |
228 |
ModifyTile(tile, MP_MAP5 | MP_MAPOWNER, OWNER_WATER, _map5[tile] | 0x08); |
|
229 |
} else { |
|
230 |
ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0); |
|
231 |
} |
|
232 |
// mark the tiles around dirty too |
|
233 |
MarkTilesAroundDirty(tile); |
|
234 |
} |
|
235 |
||
236 |
cost += _price.clear_water; |
|
237 |
} |
|
238 |
if (tile == endtile) |
|
239 |
break; |
|
240 |
tile += delta; |
|
241 |
} |
|
242 |
if (cost == 0) return CMD_ERROR; |
|
243 |
||
244 |
return cost; |
|
245 |
} |
|
246 |
||
247 |
static int32 ClearTile_Water(uint tile, byte flags) { |
|
248 |
byte m5 = _map5[tile]; |
|
249 |
uint slope; |
|
250 |
||
251 |
if (m5 <= 1) { // water and shore |
|
252 |
// Allow building on water? It's ok to build on shores. |
|
253 |
if (flags & DC_NO_WATER && m5 != 1) |
|
254 |
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
|
255 |
||
256 |
// Make sure no vehicle is on the tile |
|
257 |
if (!EnsureNoVehicle(tile)) |
|
258 |
return CMD_ERROR; |
|
259 |
||
260 |
// Make sure it's not an edge 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
|
261 |
if (!(IS_INT_INSIDE(TileX(tile), 1, MapMaxX() - 1) && |
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
|
262 |
IS_INT_INSIDE(TileY(tile), 1, MapMaxY() - 1))) |
0 | 263 |
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP); |
264 |
||
265 |
if (m5 == 0) { |
|
266 |
if (flags & DC_EXEC) |
|
267 |
DoClearSquare(tile); |
|
268 |
return _price.clear_water; |
|
269 |
} else if (m5 == 1) { |
|
270 |
slope = GetTileSlope(tile,NULL); |
|
271 |
if (slope == 8 || slope == 4 || slope == 2 || slope == 1) { |
|
272 |
if (flags & DC_EXEC) |
|
273 |
DoClearSquare(tile); |
|
274 |
return _price.clear_water; |
|
275 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
276 |
if (flags & DC_EXEC) |
0 | 277 |
DoClearSquare(tile); |
278 |
return _price.purchase_land; |
|
279 |
} else |
|
280 |
return CMD_ERROR; |
|
281 |
} else if ((m5 & 0x10) == 0x10) { |
|
282 |
// shiplift |
|
283 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
284 |
static const TileIndexDiffC _shiplift_tomiddle_offs[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
285 |
{ 0, 0}, {0, 0}, { 0, 0}, {0, 0}, // middle |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
286 |
{-1, 0}, {0, 1}, { 1, 0}, {0, -1}, // lower |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
287 |
{ 1, 0}, {0, -1}, {-1, 0}, {0, 1}, // upper |
0 | 288 |
}; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
289 |
|
0 | 290 |
if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
291 |
// don't allow water to delete it. |
|
292 |
if (_current_player == OWNER_WATER) return CMD_ERROR; |
|
293 |
// move to the middle tile.. |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
294 |
return RemoveShiplift(tile + ToTileIndexDiff(_shiplift_tomiddle_offs[m5 & 0xF]), flags); |
0 | 295 |
} else { |
296 |
// ship depot |
|
297 |
if (flags & DC_AUTO) |
|
298 |
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
299 |
||
300 |
if (m5 == 0x80 || m5 == 0x82) {} |
|
301 |
else if (m5 == 0x81) { tile -= TILE_XY(1,0); } |
|
302 |
else if (m5 == 0x83) { tile -= TILE_XY(0,1); } |
|
303 |
else |
|
304 |
return CMD_ERROR; |
|
305 |
||
306 |
return RemoveShipDepot(tile,flags); |
|
307 |
} |
|
308 |
} |
|
309 |
||
310 |
// return true if a tile is a water tile. |
|
1048 | 311 |
static bool IsWateredTile(TileIndex tile) |
0 | 312 |
{ |
313 |
byte m5 = _map5[tile]; |
|
1048 | 314 |
|
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
315 |
switch (GetTileType(tile)) { |
1048 | 316 |
case MP_WATER: |
317 |
// true, if not coast/riverbank |
|
318 |
return m5 != 1; |
|
319 |
||
320 |
case MP_STATION: |
|
321 |
// returns true if it is a dock-station |
|
322 |
// m5 inside values is m5 < 75 all stations, 83 <= m5 <= 114 new airports |
|
323 |
return !(m5 < 75 || (m5 >= 83 && m5 <= 114)); |
|
324 |
||
325 |
case MP_TUNNELBRIDGE: |
|
326 |
// true, if tile is middle part of bridge with water underneath |
|
327 |
return (m5 & 0xF8) == 0xC8; |
|
328 |
||
329 |
default: |
|
330 |
return false; |
|
331 |
} |
|
0 | 332 |
} |
333 |
||
334 |
// draw a canal styled water tile with dikes around |
|
335 |
void DrawCanalWater(uint tile) |
|
336 |
{ |
|
337 |
uint wa; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
338 |
|
0 | 339 |
// determine the edges around with water. |
340 |
wa = IsWateredTile(TILE_ADDXY(tile, -1, 0)) << 0; |
|
341 |
wa += IsWateredTile(TILE_ADDXY(tile, 0, 1)) << 1; |
|
342 |
wa += IsWateredTile(TILE_ADDXY(tile, 1, 0)) << 2; |
|
343 |
wa += IsWateredTile(TILE_ADDXY(tile, 0, -1)) << 3; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
344 |
|
0 | 345 |
if (!(wa & 1)) DrawGroundSprite(SPR_CANALS_BASE + 57); |
346 |
if (!(wa & 2)) DrawGroundSprite(SPR_CANALS_BASE + 58); |
|
347 |
if (!(wa & 4)) DrawGroundSprite(SPR_CANALS_BASE + 59); |
|
348 |
if (!(wa & 8)) DrawGroundSprite(SPR_CANALS_BASE + 60); |
|
349 |
||
350 |
// right corner |
|
351 |
if ((wa & 3) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 4); |
|
352 |
else if ((wa & 3) == 3 && !IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 8); |
|
353 |
||
354 |
// bottom corner |
|
355 |
if ((wa & 6) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 5); |
|
356 |
else if ((wa & 6) == 6 && !IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 9); |
|
357 |
||
358 |
// left corner |
|
359 |
if ((wa & 12) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 6); |
|
360 |
else if ((wa & 12) == 12 && !IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 10); |
|
361 |
||
362 |
// upper corner |
|
363 |
if ((wa & 9) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 7); |
|
364 |
else if ((wa & 9) == 9 && !IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 11); |
|
365 |
} |
|
366 |
||
367 |
typedef struct LocksDrawTileStruct { |
|
368 |
int8 delta_x, delta_y, delta_z; |
|
369 |
byte width, height, depth; |
|
370 |
SpriteID image; |
|
371 |
} LocksDrawTileStruct; |
|
372 |
||
373 |
#include "table/water_land.h" |
|
374 |
||
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
375 |
static void DrawWaterStuff(TileInfo *ti, const WaterDrawTileStruct *wdts, |
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
376 |
uint32 palette, uint base |
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
377 |
) |
0 | 378 |
{ |
379 |
uint32 image; |
|
380 |
||
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
381 |
DrawGroundSprite(wdts++->image); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
382 |
|
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
383 |
for (; wdts->delta_x != 0x80; wdts++) { |
0 | 384 |
image = wdts->image + base; |
385 |
if (_display_opt & DO_TRANS_BUILDINGS) { |
|
497
4d1c889526ee
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
386 |
image = (image & 0x3FFF) | 0x03224000; |
4d1c889526ee
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
387 |
} else { |
0 | 388 |
image |= palette; |
389 |
} |
|
390 |
AddSortableSpriteToDraw(image, ti->x + wdts->delta_x, ti->y + wdts->delta_y, wdts->width, wdts->height, wdts->unk, ti->z + wdts->delta_z); |
|
391 |
} |
|
392 |
} |
|
393 |
||
394 |
static void DrawTile_Water(TileInfo *ti) |
|
395 |
{ |
|
396 |
// draw water tile |
|
397 |
if (ti->map5 == 0) { |
|
398 |
DrawGroundSprite(0xFDD); |
|
399 |
if (ti->z != 0) DrawCanalWater(ti->tile); |
|
400 |
return; |
|
401 |
} |
|
402 |
||
403 |
// draw shore |
|
404 |
if (ti->map5 == 1) { |
|
405 |
assert(ti->tileh < 16); |
|
406 |
DrawGroundSprite(_water_shore_sprites[ti->tileh]); |
|
407 |
return; |
|
408 |
} |
|
409 |
||
410 |
// draw shiplift |
|
411 |
if ((ti->map5 & 0xF0) == 0x10) { |
|
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
412 |
const WaterDrawTileStruct *t = _shiplift_display_seq[ti->map5 & 0xF]; |
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
413 |
DrawWaterStuff(ti, t, 0, ti->z > t[3].delta_y ? 24 : 0); |
0 | 414 |
return; |
415 |
} |
|
416 |
||
417 |
DrawWaterStuff(ti, _shipdepot_display_seq[ti->map5 & 0x7F], PLAYER_SPRITE_COLOR(_map_owner[ti->tile]), 0); |
|
418 |
} |
|
419 |
||
420 |
void DrawShipDepotSprite(int x, int y, int image) |
|
421 |
{ |
|
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
422 |
const WaterDrawTileStruct *wdts = _shipdepot_display_seq[image]; |
0 | 423 |
|
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
424 |
DrawSprite(wdts++->image, x, y); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
425 |
|
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
426 |
for (; wdts->delta_x != 0x80; wdts++) { |
0 | 427 |
Point pt = RemapCoords(wdts->delta_x, wdts->delta_y, wdts->delta_z); |
428 |
DrawSprite(wdts->image + PLAYER_SPRITE_COLOR(_local_player), x + pt.x, y + pt.y); |
|
429 |
} |
|
430 |
} |
|
431 |
||
432 |
||
410 | 433 |
static uint GetSlopeZ_Water(TileInfo *ti) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
434 |
{ |
0 | 435 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z; |
436 |
} |
|
437 |
||
410 | 438 |
static uint GetSlopeTileh_Water(TileInfo *ti) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
439 |
{ |
39 | 440 |
return ti->tileh; |
441 |
} |
|
442 |
||
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
410
diff
changeset
|
443 |
static void GetAcceptedCargo_Water(uint tile, AcceptedCargo ac) |
0 | 444 |
{ |
445 |
/* not used */ |
|
446 |
} |
|
447 |
||
448 |
static void GetTileDesc_Water(uint tile, TileDesc *td) |
|
449 |
{ |
|
1041
94db182c3614
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
450 |
if (_map5[tile] == 0 && TilePixelHeight(tile) == 0) |
0 | 451 |
td->str = STR_3804_WATER; |
452 |
else if (_map5[tile] == 0) |
|
453 |
td->str = STR_LANDINFO_CANAL; |
|
454 |
else if (_map5[tile] == 1) |
|
455 |
td->str = STR_3805_COAST_OR_RIVERBANK; |
|
456 |
else if ((_map5[tile]&0xF0) == 0x10) |
|
457 |
td->str = STR_LANDINFO_LOCK; |
|
458 |
else |
|
459 |
td->str = STR_3806_SHIP_DEPOT; |
|
460 |
||
461 |
td->owner = _map_owner[tile]; |
|
462 |
} |
|
463 |
||
464 |
static void AnimateTile_Water(uint tile) |
|
465 |
{ |
|
466 |
/* not used */ |
|
467 |
} |
|
468 |
||
1075 | 469 |
static void TileLoopWaterHelper(TileIndex tile, const TileIndexDiffC *offs) |
0 | 470 |
{ |
1075 | 471 |
TileIndex target = TILE_ADD(tile, ToTileIndexDiff(offs[0])); |
0 | 472 |
|
473 |
// type of this tile mustn't be water already. |
|
1075 | 474 |
if (IsTileType(target, MP_WATER)) |
0 | 475 |
return; |
476 |
||
1075 | 477 |
if (TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[1]))) != 0 || |
478 |
TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[2]))) != 0) |
|
479 |
return; |
|
480 |
||
481 |
if (TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[3]))) != 0 || |
|
482 |
TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[4]))) != 0) { |
|
0 | 483 |
// make coast.. |
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
484 |
switch (GetTileType(target)) { |
1076
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
485 |
case MP_RAILWAY: { |
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
486 |
uint slope = GetTileSlope(target, NULL); |
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
487 |
byte tracks = _map5[target] & 0x3F; |
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
488 |
if (!( |
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
489 |
(slope == 1 && tracks == 0x20) || |
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
490 |
(slope == 2 && tracks == 0x04) || |
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
491 |
(slope == 4 && tracks == 0x10) || |
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
492 |
(slope == 8 && tracks == 0x08))) |
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
493 |
break; |
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
494 |
} |
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
495 |
/* FALLTHROUGH */ |
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
496 |
|
1075 | 497 |
case MP_CLEAR: |
498 |
case MP_TREES: |
|
499 |
_current_player = OWNER_WATER; |
|
500 |
if (DoCommandByTile(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR) != CMD_ERROR) { |
|
501 |
ModifyTile( |
|
502 |
target, |
|
503 |
MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | |
|
504 |
MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, |
|
505 |
OWNER_WATER, 1 |
|
506 |
); |
|
507 |
} |
|
508 |
break; |
|
509 |
||
1091
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1076
diff
changeset
|
510 |
case MP_TUNNELBRIDGE: |
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1076
diff
changeset
|
511 |
// Middle part of bridge with clear land below? |
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1076
diff
changeset
|
512 |
if ((_map5[target] & 0xF8) == 0xC0) { |
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1076
diff
changeset
|
513 |
_map5[target] |= 0x08; |
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1076
diff
changeset
|
514 |
MarkTileDirtyByTile(tile); |
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1076
diff
changeset
|
515 |
} |
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1076
diff
changeset
|
516 |
break; |
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1076
diff
changeset
|
517 |
|
1075 | 518 |
default: |
519 |
break; |
|
0 | 520 |
} |
521 |
} else { |
|
1075 | 522 |
if (IsTileType(target, MP_TUNNELBRIDGE)) { |
523 |
byte m5 = _map5[target]; |
|
524 |
if ((m5 & 0xF8) == 0xC8 || (m5 & 0xF8) == 0xF0) |
|
0 | 525 |
return; |
526 |
||
1075 | 527 |
if ((m5 & 0xC0) == 0xC0) { |
528 |
ModifyTile(target, MP_MAPOWNER | MP_MAP5, OWNER_WATER, (m5 & ~0x38) | 0x8); |
|
0 | 529 |
return; |
530 |
} |
|
531 |
} |
|
532 |
||
533 |
_current_player = OWNER_WATER; |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
534 |
{ |
1075 | 535 |
Vehicle *v = FindVehicleBetween(target, target, 0); |
536 |
if (v != NULL) FloodVehicle(v); |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
537 |
} |
1075 | 538 |
|
539 |
if (DoCommandByTile(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR) != CMD_ERROR) { |
|
540 |
ModifyTile( |
|
541 |
target, |
|
542 |
MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | |
|
543 |
MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, |
|
544 |
OWNER_WATER, |
|
545 |
0 |
|
546 |
); |
|
547 |
} |
|
0 | 548 |
} |
549 |
} |
|
550 |
||
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
551 |
static void FloodVehicle(Vehicle *v) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
552 |
{ |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
553 |
Vehicle *u; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
554 |
if (!(v->vehstatus & VS_CRASHED)) { |
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
555 |
uint16 pass = 0; |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
556 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
557 |
if (v->type == VEH_Road) { // flood bus/truck |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
558 |
pass = 1; // driver |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
559 |
if (v->cargo_type == CT_PASSENGERS) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
560 |
pass += v->cargo_count; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
561 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
562 |
v->vehstatus |= VS_CRASHED; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
563 |
v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast |
588 | 564 |
RebuildVehicleLists(); |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
565 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
566 |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
567 |
else if (v->type == VEH_Train) { |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
568 |
v = GetFirstVehicleInChain(v); |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
569 |
u = v; |
1132
71a2168ceee1
(svn r1633) -Fix: [1040119] Flood and wagons in depot
darkvater
parents:
1093
diff
changeset
|
570 |
if (v->subtype == TS_Front_Engine) pass = 4; // driver |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
571 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
572 |
// crash all wagons, and count passangers |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
573 |
BEGIN_ENUM_WAGONS(v) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
574 |
if (v->cargo_type == CT_PASSENGERS) pass += v->cargo_count; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
575 |
v->vehstatus |= VS_CRASHED; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
576 |
END_ENUM_WAGONS(v) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
577 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
578 |
v = u; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
579 |
v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast |
588 | 580 |
RebuildVehicleLists(); |
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
581 |
} else |
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
582 |
return; |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
583 |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
726
diff
changeset
|
584 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
585 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
586 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
587 |
SetDParam(0, pass); |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
588 |
AddNewsItem(STR_B006_FLOOD_VEHICLE_DESTROYED, |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
589 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
590 |
v->index, |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
591 |
0); |
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1313
diff
changeset
|
592 |
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); // show cool destruction effects |
541 | 593 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); // create sound |
714
503e96f37d46
(svn r1166) Fix: [ 1040119 ] Flooded wagons in depots don't keep constantly exploding any more
dominik
parents:
679
diff
changeset
|
594 |
} |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
595 |
} |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
596 |
|
0 | 597 |
// called from tunnelbridge_cmd |
598 |
void TileLoop_Water(uint tile) |
|
599 |
{ |
|
600 |
int i; |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
601 |
static const TileIndexDiffC _tile_loop_offs_array[][5] = { |
0 | 602 |
// tile to mod shore? shore? |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
603 |
{{-1, 0}, {0, 0}, {0, 1}, {-1, 0}, {-1, 1}}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
604 |
{{ 0, 1}, {0, 1}, {1, 1}, { 0, 2}, { 1, 2}}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
605 |
{{ 1, 0}, {1, 0}, {1, 1}, { 2, 0}, { 2, 1}}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
606 |
{{ 0, -1}, {0, 0}, {1, 0}, { 0, -1}, { 1, -1}} |
0 | 607 |
}; |
608 |
||
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
|
609 |
if (IS_INT_INSIDE(TileX(tile), 1, MapSizeX() - 3 + 1) && |
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
|
610 |
IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) { |
0 | 611 |
for(i=0; i!=4; i++) |
612 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[i]); |
|
613 |
} |
|
314 | 614 |
// _current_player can be changed by TileLoopWaterHelper.. reset it back |
615 |
// here |
|
616 |
_current_player = OWNER_NONE; |
|
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
617 |
|
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
618 |
// edges |
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
|
619 |
if (TileX(tile) == 0 && IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) //NE |
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
620 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[2]); |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
621 |
|
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
|
622 |
if (TileX(tile) == (MapSizeX() - 2) && IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) //SW |
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
623 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[0]); |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
624 |
|
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
|
625 |
if (TileY(tile) == 0 && IS_INT_INSIDE(TileX(tile), 1, MapSizeX() - 3 + 1)) //NW |
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
626 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[1]); |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
627 |
|
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
|
628 |
if (TileY(tile) == (MapSizeY() - 2) && IS_INT_INSIDE(TileX(tile), 1, MapSizeX() - 3 + 1)) //SE |
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
629 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[3]); |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
630 |
|
0 | 631 |
} |
632 |
||
633 |
||
634 |
static const byte _coast_tracks[16] = {0, 32, 4, 0, 16, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0}; |
|
635 |
static const byte _shipdepot_tracks[4] = {1,1,2,2}; |
|
636 |
static const byte _shiplift_tracks[12] = {1,2,1,2,1,2,1,2,1,2,1,2}; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
637 |
static uint32 GetTileTrackStatus_Water(uint tile, TransportType mode) |
0 | 638 |
{ |
639 |
uint m5; |
|
640 |
uint b; |
|
641 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
642 |
if (mode != TRANSPORT_WATER) |
0 | 643 |
return 0; |
644 |
||
645 |
m5 = _map5[tile]; |
|
646 |
if (m5 == 0) |
|
647 |
return 0x3F3F; |
|
648 |
||
649 |
if (m5 == 1) { |
|
650 |
b = _coast_tracks[GetTileSlope(tile, NULL)&0xF]; |
|
651 |
return b + (b<<8); |
|
652 |
} |
|
653 |
||
654 |
if ( (m5 & 0x10) == 0x10) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
655 |
// |
0 | 656 |
b = _shiplift_tracks[m5 & 0xF]; |
657 |
return b + (b<<8); |
|
658 |
} |
|
659 |
||
660 |
if (!(m5 & 0x80)) |
|
661 |
return 0; |
|
662 |
||
663 |
b = _shipdepot_tracks[m5 & 0x7F]; |
|
664 |
return b + (b<<8); |
|
665 |
} |
|
666 |
||
667 |
extern void ShowShipDepotWindow(uint tile); |
|
668 |
||
669 |
static void ClickTile_Water(uint tile) |
|
670 |
{ |
|
671 |
byte m5 = _map5[tile] - 0x80; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
672 |
|
0 | 673 |
if (IS_BYTE_INSIDE(m5, 0, 3+1)) { |
674 |
if (m5 & 1) |
|
675 |
tile += (m5==1) ? TILE_XY(-1,0) : TILE_XY(0,-1); |
|
676 |
ShowShipDepotWindow(tile); |
|
677 |
} |
|
678 |
} |
|
679 |
||
680 |
static void ChangeTileOwner_Water(uint tile, byte old_player, byte new_player) |
|
681 |
{ |
|
682 |
if (_map_owner[tile] != old_player) |
|
683 |
return; |
|
684 |
||
685 |
if (new_player != 255) { |
|
686 |
_map_owner[tile] = new_player; |
|
687 |
} else { |
|
688 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
689 |
} |
|
690 |
} |
|
691 |
||
692 |
static uint32 VehicleEnter_Water(Vehicle *v, uint tile, int x, int y) |
|
693 |
{ |
|
694 |
return 0; |
|
695 |
} |
|
696 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1091
diff
changeset
|
697 |
void InitializeDock(void) |
0 | 698 |
{ |
699 |
_last_built_ship_depot_tile = 0; |
|
700 |
} |
|
701 |
||
702 |
const TileTypeProcs _tile_type_water_procs = { |
|
703 |
DrawTile_Water, /* draw_tile_proc */ |
|
704 |
GetSlopeZ_Water, /* get_slope_z_proc */ |
|
705 |
ClearTile_Water, /* clear_tile_proc */ |
|
706 |
GetAcceptedCargo_Water, /* get_accepted_cargo_proc */ |
|
707 |
GetTileDesc_Water, /* get_tile_desc_proc */ |
|
708 |
GetTileTrackStatus_Water, /* get_tile_track_status_proc */ |
|
709 |
ClickTile_Water, /* click_tile_proc */ |
|
710 |
AnimateTile_Water, /* animate_tile_proc */ |
|
711 |
TileLoop_Water, /* tile_loop_clear */ |
|
712 |
ChangeTileOwner_Water, /* change_tile_owner_clear */ |
|
713 |
NULL, /* get_produced_cargo_proc */ |
|
714 |
VehicleEnter_Water, /* vehicle_enter_tile_proc */ |
|
715 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 716 |
GetSlopeTileh_Water, /* get_slope_tileh_proc */ |
0 | 717 |
}; |
718 |