author | tron |
Wed, 15 Dec 2004 22:18:54 +0000 | |
changeset 679 | e959706a3e4d |
parent 588 | 1b60458bdc29 |
child 714 | e3b9eda8dc45 |
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" |
0 | 5 |
#include "vehicle.h" |
6 |
#include "viewport.h" |
|
7 |
#include "command.h" |
|
8 |
#include "town.h" |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
9 |
#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
|
10 |
#include "sound.h" |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
11 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
12 |
static void FloodVehicle(Vehicle *v); |
0 | 13 |
|
14 |
bool IsShipDepotTile(TileIndex tile) |
|
15 |
{ |
|
16 |
return IS_TILETYPE(tile, MP_WATER) && (_map5[tile]&~3) == 0x80; |
|
17 |
} |
|
18 |
||
410 | 19 |
static bool IsClearWaterTile(uint tile) |
0 | 20 |
{ |
21 |
TileInfo ti; |
|
22 |
FindLandscapeHeightByTile(&ti, tile); |
|
23 |
return (ti.type == MP_WATER && ti.tileh == 0 && ti.map5 == 0); |
|
24 |
} |
|
25 |
||
26 |
/* Build a ship depot |
|
27 |
* p1 - direction |
|
28 |
*/ |
|
29 |
||
30 |
int32 CmdBuildShipDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
31 |
{ |
|
32 |
uint tile, tile2; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
33 |
|
0 | 34 |
int32 cost, ret; |
35 |
Depot *dep; |
|
36 |
||
37 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
38 |
||
39 |
tile = TILE_FROM_XY(x,y); |
|
40 |
if (!EnsureNoVehicle(tile)) |
|
41 |
return CMD_ERROR; |
|
42 |
||
43 |
tile2 = tile + (p1 ? TILE_XY(0,1) : TILE_XY(1,0)); |
|
44 |
if (!EnsureNoVehicle(tile2)) |
|
45 |
return CMD_ERROR; |
|
46 |
||
47 |
if (!IsClearWaterTile(tile) || !IsClearWaterTile(tile2)) |
|
48 |
return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER); |
|
49 |
||
50 |
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
51 |
if (ret == CMD_ERROR) return CMD_ERROR; |
|
52 |
ret = DoCommandByTile(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
53 |
if (ret == CMD_ERROR) |
|
54 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
55 |
|
0 | 56 |
// pretend that we're not making land from the water even though we actually are. |
57 |
cost = 0; |
|
58 |
||
59 |
dep = AllocateDepot(); |
|
60 |
if (dep == NULL) |
|
61 |
return CMD_ERROR; |
|
62 |
||
63 |
if (flags & DC_EXEC) { |
|
64 |
dep->xy = tile; |
|
65 |
_last_built_ship_depot_tile = tile; |
|
66 |
dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
|
67 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
68 |
ModifyTile(tile, |
0 | 69 |
MP_SETTYPE(MP_WATER) | MP_MAPOWNER_CURRENT | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, |
70 |
(0x80 + p1*2) |
|
71 |
); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
72 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
73 |
ModifyTile(tile2, |
0 | 74 |
MP_SETTYPE(MP_WATER) | MP_MAPOWNER_CURRENT | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, |
75 |
(0x81 + p1*2) |
|
76 |
); |
|
77 |
} |
|
78 |
||
79 |
return cost + _price.build_ship_depot; |
|
80 |
} |
|
81 |
||
82 |
static int32 RemoveShipDepot(uint tile, uint32 flags) |
|
83 |
{ |
|
84 |
uint tile2; |
|
85 |
||
86 |
if (!CheckTileOwnership(tile)) |
|
87 |
return CMD_ERROR; |
|
88 |
||
89 |
if (!EnsureNoVehicle(tile)) |
|
90 |
return CMD_ERROR; |
|
91 |
||
92 |
tile2 = tile + ((_map5[tile] & 2) ? TILE_XY(0,1) : TILE_XY(1,0)); |
|
93 |
||
94 |
if (!EnsureNoVehicle(tile2)) |
|
95 |
return CMD_ERROR; |
|
96 |
||
97 |
if (flags & DC_EXEC) { |
|
98 |
Depot *d; |
|
99 |
||
100 |
// convert the cleared tiles to water |
|
101 |
ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0); |
|
102 |
ModifyTile(tile2, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0); |
|
103 |
||
104 |
// Kill the entry from the depot table |
|
105 |
for(d=_depots; d->xy != tile; d++) {} |
|
106 |
d->xy = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
107 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
108 |
DeleteWindowById(WC_VEHICLE_DEPOT, tile); |
0 | 109 |
} |
110 |
||
111 |
return _price.remove_ship_depot; |
|
112 |
} |
|
113 |
||
114 |
// build a shiplift |
|
115 |
static int32 DoBuildShiplift(uint tile, int dir, uint32 flags) |
|
116 |
{ |
|
117 |
int32 ret; |
|
118 |
int delta; |
|
119 |
||
120 |
// middle tile |
|
121 |
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
122 |
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
|
123 |
|
0 | 124 |
delta = _tileoffs_by_dir[dir]; |
125 |
// lower tile |
|
126 |
ret = DoCommandByTile(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
127 |
if (ret == CMD_ERROR) return CMD_ERROR; |
|
128 |
if (GetTileSlope(tile - delta, NULL)) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
129 |
||
130 |
// upper tile |
|
131 |
ret = DoCommandByTile(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
132 |
if (ret == CMD_ERROR) return CMD_ERROR; |
|
133 |
if (GetTileSlope(tile + delta, NULL)) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
134 |
||
135 |
if (flags & DC_EXEC) { |
|
136 |
ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0x10 + dir); |
|
137 |
ModifyTile(tile - delta, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0x14 + dir); |
|
138 |
ModifyTile(tile + delta, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0x18 + dir); |
|
139 |
} |
|
140 |
||
141 |
return _price.clear_water * 22 >> 3; |
|
142 |
} |
|
143 |
||
144 |
static int32 RemoveShiplift(uint tile, uint32 flags) |
|
145 |
{ |
|
146 |
int delta = _tileoffs_by_dir[_map5[tile] & 3]; |
|
147 |
||
148 |
// make sure no vehicle is on the tile. |
|
149 |
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(tile + delta) || !EnsureNoVehicle(tile - delta)) |
|
150 |
return CMD_ERROR; |
|
151 |
||
152 |
if (flags & DC_EXEC) { |
|
153 |
DoClearSquare(tile); |
|
154 |
DoClearSquare(tile + delta); |
|
155 |
DoClearSquare(tile - delta); |
|
156 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
157 |
|
0 | 158 |
return _price.clear_water * 2; |
159 |
} |
|
160 |
||
161 |
static void MarkTilesAroundDirty(uint tile) |
|
162 |
{ |
|
163 |
MarkTileDirtyByTile(TILE_ADDXY(tile, 0, 1)); |
|
164 |
MarkTileDirtyByTile(TILE_ADDXY(tile, 0, -1)); |
|
165 |
MarkTileDirtyByTile(TILE_ADDXY(tile, 1, 0)); |
|
166 |
MarkTileDirtyByTile(TILE_ADDXY(tile, -1, 0)); |
|
167 |
} |
|
168 |
||
169 |
int32 CmdBuildLock(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
170 |
{ |
|
171 |
uint tile = TILE_FROM_XY(x,y); |
|
172 |
int32 ret; |
|
173 |
uint th; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
174 |
th = GetTileSlope(tile, NULL); |
0 | 175 |
|
176 |
if (th==3 || th==6 || th==9 || th==12) { |
|
177 |
static const byte _shiplift_dirs[16] = {0,0,0,2,0,0,1,0,0,3,0,0,0}; |
|
178 |
ret = DoBuildShiplift(tile, _shiplift_dirs[th], flags); |
|
179 |
return ret; |
|
180 |
} |
|
181 |
else |
|
182 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
183 |
||
184 |
return 0; |
|
185 |
} |
|
186 |
||
187 |
int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
188 |
{ |
|
189 |
uint tile = TILE_FROM_XY(x,y); |
|
190 |
int32 ret; |
|
191 |
uint th; |
|
192 |
uint endtile = (uint)p1; |
|
193 |
int delta; |
|
194 |
int32 cost; |
|
195 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
196 |
||
197 |
// move in which direction? |
|
198 |
delta = (GET_TILE_X(tile) == GET_TILE_X(endtile)) ? TILE_XY(0,1) : TILE_XY(1,0); |
|
199 |
if (endtile < tile) delta = -delta; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
200 |
|
0 | 201 |
cost = 0; |
202 |
for(;;) { |
|
203 |
ret = 0; |
|
204 |
th = GetTileSlope(tile, NULL); |
|
205 |
if(th!=0) |
|
206 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
207 |
||
208 |
// can't make water of water! |
|
209 |
if (IS_TILETYPE(tile, MP_WATER)) { |
|
210 |
_error_message = STR_1007_ALREADY_BUILT; |
|
211 |
} else { |
|
212 |
||
213 |
/* is middle piece of a bridge? */ |
|
214 |
if (IS_TILETYPE(tile, MP_TUNNELBRIDGE) && _map5[tile] & 0x40) { /* build under bridge */ |
|
215 |
if(_map5[tile] & 0x20) { // transport route under bridge |
|
216 |
_error_message = STR_5800_OBJECT_IN_THE_WAY; |
|
217 |
ret = CMD_ERROR; |
|
218 |
} |
|
219 |
else if (_map5[tile] & 0x18) { // already water under bridge |
|
220 |
_error_message = STR_1007_ALREADY_BUILT; |
|
221 |
ret = CMD_ERROR; |
|
222 |
} |
|
223 |
||
224 |
/* no bridge? then try to clear it. */ |
|
225 |
} else { |
|
226 |
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
227 |
} |
|
228 |
if (ret == CMD_ERROR) return ret; |
|
229 |
cost += ret; |
|
230 |
||
231 |
/* execute modifications */ |
|
232 |
if (flags & DC_EXEC) { |
|
233 |
if(IS_TILETYPE(tile, MP_TUNNELBRIDGE)) { |
|
234 |
// change owner to OWNER_WATER and set land under bridge bit to water |
|
235 |
ModifyTile(tile, MP_MAP5 | MP_MAPOWNER, OWNER_WATER, _map5[tile] | 0x08); |
|
236 |
} else { |
|
237 |
ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0); |
|
238 |
} |
|
239 |
// mark the tiles around dirty too |
|
240 |
MarkTilesAroundDirty(tile); |
|
241 |
} |
|
242 |
||
243 |
cost += _price.clear_water; |
|
244 |
} |
|
245 |
if (tile == endtile) |
|
246 |
break; |
|
247 |
tile += delta; |
|
248 |
} |
|
249 |
if (cost == 0) return CMD_ERROR; |
|
250 |
||
251 |
return cost; |
|
252 |
} |
|
253 |
||
254 |
static int32 ClearTile_Water(uint tile, byte flags) { |
|
255 |
byte m5 = _map5[tile]; |
|
256 |
uint slope; |
|
257 |
||
258 |
if (m5 <= 1) { // water and shore |
|
259 |
// Allow building on water? It's ok to build on shores. |
|
260 |
if (flags & DC_NO_WATER && m5 != 1) |
|
261 |
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
|
262 |
||
263 |
// Make sure no vehicle is on the tile |
|
264 |
if (!EnsureNoVehicle(tile)) |
|
265 |
return CMD_ERROR; |
|
266 |
||
267 |
// Make sure it's not an edge tile. |
|
268 |
if (!(IS_INT_INSIDE(GET_TILE_X(tile),1,TILE_X_MAX-1) && |
|
269 |
IS_INT_INSIDE(GET_TILE_Y(tile),1,TILE_Y_MAX-1))) |
|
270 |
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP); |
|
271 |
||
272 |
if (m5 == 0) { |
|
273 |
if (flags & DC_EXEC) |
|
274 |
DoClearSquare(tile); |
|
275 |
return _price.clear_water; |
|
276 |
} else if (m5 == 1) { |
|
277 |
slope = GetTileSlope(tile,NULL); |
|
278 |
if (slope == 8 || slope == 4 || slope == 2 || slope == 1) { |
|
279 |
if (flags & DC_EXEC) |
|
280 |
DoClearSquare(tile); |
|
281 |
return _price.clear_water; |
|
282 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
283 |
if (flags & DC_EXEC) |
0 | 284 |
DoClearSquare(tile); |
285 |
return _price.purchase_land; |
|
286 |
} else |
|
287 |
return CMD_ERROR; |
|
288 |
} else if ((m5 & 0x10) == 0x10) { |
|
289 |
// shiplift |
|
290 |
||
291 |
static const TileIndexDiff _shiplift_tomiddle_offs[12] = { |
|
292 |
0,0,0,0, // middle |
|
293 |
TILE_XY(-1, 0),TILE_XY(0, 1),TILE_XY(1, 0),TILE_XY(0, -1), // lower |
|
294 |
TILE_XY(1, 0),TILE_XY(0, -1),TILE_XY(-1, 0),TILE_XY(0, 1), // upper |
|
295 |
}; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
296 |
|
0 | 297 |
if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
298 |
// don't allow water to delete it. |
|
299 |
if (_current_player == OWNER_WATER) return CMD_ERROR; |
|
300 |
// move to the middle tile.. |
|
301 |
return RemoveShiplift(tile + _shiplift_tomiddle_offs[m5 & 0xF], flags); |
|
302 |
} else { |
|
303 |
// ship depot |
|
304 |
if (flags & DC_AUTO) |
|
305 |
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
306 |
||
307 |
if (m5 == 0x80 || m5 == 0x82) {} |
|
308 |
else if (m5 == 0x81) { tile -= TILE_XY(1,0); } |
|
309 |
else if (m5 == 0x83) { tile -= TILE_XY(0,1); } |
|
310 |
else |
|
311 |
return CMD_ERROR; |
|
312 |
||
313 |
return RemoveShipDepot(tile,flags); |
|
314 |
} |
|
315 |
} |
|
316 |
||
317 |
// return true if a tile is a water tile. |
|
318 |
static bool IsWateredTile(uint tile) |
|
319 |
{ |
|
320 |
byte m5 = _map5[tile]; |
|
321 |
if (IS_TILETYPE(tile, MP_WATER)) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
322 |
return m5 != 1; |
0 | 323 |
} else if (IS_TILETYPE(tile, MP_STATION)) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
324 |
// returns true if it is a dock-station (m5 inside values is m5<75 all stations, |
0 | 325 |
// 83<=m5<=114 new airports |
326 |
return !(m5 < 75 || (m5 >= 83 && m5 <= 114)); |
|
327 |
} else if (IS_TILETYPE(tile, MP_TUNNELBRIDGE)) { |
|
328 |
return (m5 & 0xF8) == 0xC8; |
|
329 |
} else |
|
330 |
return false; |
|
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 |
{ |
|
462 |
if (_map5[tile] == 0 && GET_TILEHEIGHT(tile) == 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 |
||
481 |
static void TileLoopWaterHelper(uint tile, const int16 *offs) |
|
482 |
{ |
|
483 |
byte *p; |
|
484 |
||
485 |
p = &_map_type_and_height[tile]; |
|
486 |
tile += offs[0]; |
|
487 |
||
488 |
// type of this tile mustn't be water already. |
|
489 |
if (p[offs[0]] >> 4 == MP_WATER) |
|
490 |
return; |
|
491 |
||
492 |
if ( (p[offs[1]] | p[offs[2]]) & 0xF ) |
|
493 |
return; |
|
494 |
||
495 |
if ( (p[offs[3]] | p[offs[4]]) & 0xF ) { |
|
496 |
// make coast.. |
|
497 |
if (p[offs[0]] >> 4 == MP_CLEAR || p[offs[0]] >> 4 == MP_TREES) { |
|
498 |
_current_player = OWNER_WATER; |
|
499 |
if (DoCommandByTile(tile,0,0,DC_EXEC | DC_AUTO, CMD_LANDSCAPE_CLEAR) != CMD_ERROR) |
|
500 |
ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR,OWNER_WATER,1); |
|
501 |
} |
|
502 |
} else { |
|
503 |
if (IS_TILETYPE(tile, MP_TUNNELBRIDGE)) { |
|
504 |
byte m5 = _map5[tile]; |
|
505 |
if ( (m5&0xF8) == 0xC8 || (m5&0xF8) == 0xF0) |
|
506 |
return; |
|
507 |
||
508 |
if ( (m5&0xC0) == 0xC0) { |
|
509 |
ModifyTile(tile, MP_MAPOWNER | MP_MAP5,OWNER_WATER,(m5 & ~0x38)|0x8); |
|
510 |
return; |
|
511 |
} |
|
512 |
} |
|
513 |
||
514 |
_current_player = OWNER_WATER; |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
515 |
{ |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
516 |
Vehicle *v = FindVehicleBetween(tile, tile, 0); |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
517 |
if (v != NULL) {FloodVehicle(v);} |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
518 |
} |
0 | 519 |
if (DoCommandByTile(tile,0,0,DC_EXEC, CMD_LANDSCAPE_CLEAR) != CMD_ERROR) |
520 |
ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR,OWNER_WATER,0); |
|
521 |
} |
|
522 |
} |
|
523 |
||
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
524 |
static void FloodVehicle(Vehicle *v) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
525 |
{ |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
526 |
Vehicle *u; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
527 |
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
|
528 |
uint16 pass = 0; |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
529 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
530 |
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
|
531 |
pass = 1; // driver |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
532 |
if (v->cargo_type == CT_PASSENGERS) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
533 |
pass += v->cargo_count; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
534 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
535 |
v->vehstatus |= VS_CRASHED; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
536 |
v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast |
588 | 537 |
RebuildVehicleLists(); |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
538 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
539 |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
540 |
else if (v->type == VEH_Train) { |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
541 |
v = GetFirstVehicleInChain(v); |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
542 |
u = v; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
543 |
pass = 4; // driver |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
544 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
545 |
// crash all wagons, and count passangers |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
546 |
BEGIN_ENUM_WAGONS(v) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
547 |
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
|
548 |
v->vehstatus |= VS_CRASHED; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
549 |
END_ENUM_WAGONS(v) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
550 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
551 |
v = u; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
552 |
v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast |
588 | 553 |
RebuildVehicleLists(); |
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
554 |
} else |
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
555 |
return; |
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 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4); |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
558 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
559 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
560 |
SetDParam(0, pass); |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
561 |
AddNewsItem(STR_B006_FLOOD_VEHICLE_DESTROYED, |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
562 |
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
|
563 |
v->index, |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
564 |
0); |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
565 |
} |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
566 |
CreateEffectVehicleRel(v,4,4,8,EV_CRASHED_SMOKE); // show cool destruction effects |
541 | 567 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); // create sound |
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 |
|
0 | 570 |
// called from tunnelbridge_cmd |
571 |
void TileLoop_Water(uint tile) |
|
572 |
{ |
|
573 |
int i; |
|
574 |
static const TileIndexDiff _tile_loop_offs_array[4][5] = { |
|
575 |
// tile to mod shore? shore? |
|
576 |
{TILE_XY(-1,0), TILE_XY(0,0), TILE_XY(0,1), TILE_XY(-1,0), TILE_XY(-1,1)}, |
|
577 |
{TILE_XY(0,1), TILE_XY(0,1), TILE_XY(1,1), TILE_XY(0,2), TILE_XY(1,2)}, |
|
578 |
{TILE_XY(1,0), TILE_XY(1,0), TILE_XY(1,1), TILE_XY(2,0), TILE_XY(2,1)}, |
|
579 |
{TILE_XY(0,-1), TILE_XY(0,0), TILE_XY(1,0), TILE_XY(0,-1), TILE_XY(1,-1)}, |
|
580 |
}; |
|
581 |
||
582 |
if ( IS_INT_INSIDE(GET_TILE_X(tile),1,TILES_X-3+1) && |
|
583 |
IS_INT_INSIDE(GET_TILE_Y(tile),1,TILES_Y-3+1)) { |
|
584 |
for(i=0; i!=4; i++) |
|
585 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[i]); |
|
586 |
} |
|
314 | 587 |
// _current_player can be changed by TileLoopWaterHelper.. reset it back |
588 |
// here |
|
589 |
_current_player = OWNER_NONE; |
|
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
590 |
|
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
591 |
// edges |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
592 |
if ( GET_TILE_X(tile)==0 && IS_INT_INSIDE(GET_TILE_Y(tile),1,TILES_Y-3+1)) //NE |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
593 |
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
|
594 |
|
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
595 |
if ( GET_TILE_X(tile)==(TILES_X-2) && IS_INT_INSIDE(GET_TILE_Y(tile),1,TILES_Y-3+1)) //SW |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
596 |
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
|
597 |
|
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
598 |
if ( GET_TILE_Y(tile)==0 && IS_INT_INSIDE(GET_TILE_X(tile),1,TILES_X-3+1)) //NW |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
599 |
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
|
600 |
|
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
601 |
if ( GET_TILE_Y(tile)==(TILES_Y-2) && IS_INT_INSIDE(GET_TILE_X(tile),1,TILES_X-3+1)) //SE |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
602 |
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
|
603 |
|
0 | 604 |
} |
605 |
||
606 |
||
607 |
static const byte _coast_tracks[16] = {0, 32, 4, 0, 16, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0}; |
|
608 |
static const byte _shipdepot_tracks[4] = {1,1,2,2}; |
|
609 |
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
|
610 |
static uint32 GetTileTrackStatus_Water(uint tile, TransportType mode) |
0 | 611 |
{ |
612 |
uint m5; |
|
613 |
uint b; |
|
614 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
615 |
if (mode != TRANSPORT_WATER) |
0 | 616 |
return 0; |
617 |
||
618 |
m5 = _map5[tile]; |
|
619 |
if (m5 == 0) |
|
620 |
return 0x3F3F; |
|
621 |
||
622 |
if (m5 == 1) { |
|
623 |
b = _coast_tracks[GetTileSlope(tile, NULL)&0xF]; |
|
624 |
return b + (b<<8); |
|
625 |
} |
|
626 |
||
627 |
if ( (m5 & 0x10) == 0x10) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
628 |
// |
0 | 629 |
b = _shiplift_tracks[m5 & 0xF]; |
630 |
return b + (b<<8); |
|
631 |
} |
|
632 |
||
633 |
if (!(m5 & 0x80)) |
|
634 |
return 0; |
|
635 |
||
636 |
b = _shipdepot_tracks[m5 & 0x7F]; |
|
637 |
return b + (b<<8); |
|
638 |
} |
|
639 |
||
640 |
extern void ShowShipDepotWindow(uint tile); |
|
641 |
||
642 |
static void ClickTile_Water(uint tile) |
|
643 |
{ |
|
644 |
byte m5 = _map5[tile] - 0x80; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
645 |
|
0 | 646 |
if (IS_BYTE_INSIDE(m5, 0, 3+1)) { |
647 |
if (m5 & 1) |
|
648 |
tile += (m5==1) ? TILE_XY(-1,0) : TILE_XY(0,-1); |
|
649 |
ShowShipDepotWindow(tile); |
|
650 |
} |
|
651 |
} |
|
652 |
||
653 |
static void ChangeTileOwner_Water(uint tile, byte old_player, byte new_player) |
|
654 |
{ |
|
655 |
if (_map_owner[tile] != old_player) |
|
656 |
return; |
|
657 |
||
658 |
if (new_player != 255) { |
|
659 |
_map_owner[tile] = new_player; |
|
660 |
} else { |
|
661 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
662 |
} |
|
663 |
} |
|
664 |
||
665 |
static uint32 VehicleEnter_Water(Vehicle *v, uint tile, int x, int y) |
|
666 |
{ |
|
667 |
return 0; |
|
668 |
} |
|
669 |
||
670 |
void InitializeDock() |
|
671 |
{ |
|
672 |
_last_built_ship_depot_tile = 0; |
|
673 |
} |
|
674 |
||
675 |
const TileTypeProcs _tile_type_water_procs = { |
|
676 |
DrawTile_Water, /* draw_tile_proc */ |
|
677 |
GetSlopeZ_Water, /* get_slope_z_proc */ |
|
678 |
ClearTile_Water, /* clear_tile_proc */ |
|
679 |
GetAcceptedCargo_Water, /* get_accepted_cargo_proc */ |
|
680 |
GetTileDesc_Water, /* get_tile_desc_proc */ |
|
681 |
GetTileTrackStatus_Water, /* get_tile_track_status_proc */ |
|
682 |
ClickTile_Water, /* click_tile_proc */ |
|
683 |
AnimateTile_Water, /* animate_tile_proc */ |
|
684 |
TileLoop_Water, /* tile_loop_clear */ |
|
685 |
ChangeTileOwner_Water, /* change_tile_owner_clear */ |
|
686 |
NULL, /* get_produced_cargo_proc */ |
|
687 |
VehicleEnter_Water, /* vehicle_enter_tile_proc */ |
|
688 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 689 |
GetSlopeTileh_Water, /* get_slope_tileh_proc */ |
0 | 690 |
}; |
691 |