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