author | darkvater |
Fri, 03 Sep 2004 17:57:27 +0000 | |
changeset 149 | 5f7d4b21df01 |
parent 43 | 3b93861c5478 |
child 159 | 139cf78bfb28 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
3 |
#include "vehicle.h" |
|
4 |
#include "viewport.h" |
|
5 |
#include "command.h" |
|
6 |
#include "town.h" |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
7 |
#include "news.h" |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
8 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
9 |
static void FloodVehicle(Vehicle *v); |
0 | 10 |
|
11 |
bool IsShipDepotTile(TileIndex tile) |
|
12 |
{ |
|
13 |
return IS_TILETYPE(tile, MP_WATER) && (_map5[tile]&~3) == 0x80; |
|
14 |
} |
|
15 |
||
16 |
bool IsClearWaterTile(uint tile) |
|
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; |
|
30 |
||
31 |
int32 cost, ret; |
|
32 |
Depot *dep; |
|
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; |
|
52 |
||
53 |
// pretend that we're not making land from the water even though we actually are. |
|
54 |
cost = 0; |
|
55 |
||
56 |
dep = AllocateDepot(); |
|
57 |
if (dep == NULL) |
|
58 |
return CMD_ERROR; |
|
59 |
||
60 |
if (flags & DC_EXEC) { |
|
61 |
dep->xy = tile; |
|
62 |
_last_built_ship_depot_tile = tile; |
|
63 |
dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
|
64 |
||
65 |
ModifyTile(tile, |
|
66 |
MP_SETTYPE(MP_WATER) | MP_MAPOWNER_CURRENT | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, |
|
67 |
(0x80 + p1*2) |
|
68 |
); |
|
69 |
||
70 |
ModifyTile(tile2, |
|
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) { |
|
95 |
Depot *d; |
|
96 |
||
97 |
// convert the cleared tiles to water |
|
98 |
ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0); |
|
99 |
ModifyTile(tile2, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0); |
|
100 |
||
101 |
// Kill the entry from the depot table |
|
102 |
for(d=_depots; d->xy != tile; d++) {} |
|
103 |
d->xy = 0; |
|
104 |
||
105 |
DeleteWindowById(WC_VEHICLE_DEPOT, tile); |
|
106 |
} |
|
107 |
||
108 |
return _price.remove_ship_depot; |
|
109 |
} |
|
110 |
||
111 |
// build a shiplift |
|
112 |
static int32 DoBuildShiplift(uint tile, int dir, uint32 flags) |
|
113 |
{ |
|
114 |
int32 ret; |
|
115 |
int delta; |
|
116 |
||
117 |
// middle tile |
|
118 |
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
119 |
if (ret == CMD_ERROR) return CMD_ERROR; |
|
120 |
||
121 |
delta = _tileoffs_by_dir[dir]; |
|
122 |
// lower 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 |
// upper tile |
|
128 |
ret = DoCommandByTile(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
129 |
if (ret == CMD_ERROR) return CMD_ERROR; |
|
130 |
if (GetTileSlope(tile + delta, NULL)) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
131 |
||
132 |
if (flags & DC_EXEC) { |
|
133 |
ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0x10 + dir); |
|
134 |
ModifyTile(tile - delta, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0x14 + dir); |
|
135 |
ModifyTile(tile + delta, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0x18 + dir); |
|
136 |
} |
|
137 |
||
138 |
return _price.clear_water * 22 >> 3; |
|
139 |
} |
|
140 |
||
141 |
static int32 RemoveShiplift(uint tile, uint32 flags) |
|
142 |
{ |
|
143 |
int delta = _tileoffs_by_dir[_map5[tile] & 3]; |
|
144 |
||
145 |
// make sure no vehicle is on the tile. |
|
146 |
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(tile + delta) || !EnsureNoVehicle(tile - delta)) |
|
147 |
return CMD_ERROR; |
|
148 |
||
149 |
if (flags & DC_EXEC) { |
|
150 |
DoClearSquare(tile); |
|
151 |
DoClearSquare(tile + delta); |
|
152 |
DoClearSquare(tile - delta); |
|
153 |
} |
|
154 |
||
155 |
return _price.clear_water * 2; |
|
156 |
} |
|
157 |
||
158 |
static void MarkTilesAroundDirty(uint tile) |
|
159 |
{ |
|
160 |
MarkTileDirtyByTile(TILE_ADDXY(tile, 0, 1)); |
|
161 |
MarkTileDirtyByTile(TILE_ADDXY(tile, 0, -1)); |
|
162 |
MarkTileDirtyByTile(TILE_ADDXY(tile, 1, 0)); |
|
163 |
MarkTileDirtyByTile(TILE_ADDXY(tile, -1, 0)); |
|
164 |
} |
|
165 |
||
166 |
int32 CmdBuildLock(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
167 |
{ |
|
168 |
uint tile = TILE_FROM_XY(x,y); |
|
169 |
int32 ret; |
|
170 |
uint th; |
|
171 |
th = GetTileSlope(tile, NULL); |
|
172 |
||
173 |
if (th==3 || th==6 || th==9 || th==12) { |
|
174 |
static const byte _shiplift_dirs[16] = {0,0,0,2,0,0,1,0,0,3,0,0,0}; |
|
175 |
ret = DoBuildShiplift(tile, _shiplift_dirs[th], flags); |
|
176 |
return ret; |
|
177 |
} |
|
178 |
else |
|
179 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
180 |
||
181 |
return 0; |
|
182 |
} |
|
183 |
||
184 |
int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
185 |
{ |
|
186 |
uint tile = TILE_FROM_XY(x,y); |
|
187 |
int32 ret; |
|
188 |
uint th; |
|
189 |
uint endtile = (uint)p1; |
|
190 |
int delta; |
|
191 |
int32 cost; |
|
192 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
193 |
||
194 |
// move in which direction? |
|
195 |
delta = (GET_TILE_X(tile) == GET_TILE_X(endtile)) ? TILE_XY(0,1) : TILE_XY(1,0); |
|
196 |
if (endtile < tile) delta = -delta; |
|
197 |
||
198 |
cost = 0; |
|
199 |
for(;;) { |
|
200 |
ret = 0; |
|
201 |
th = GetTileSlope(tile, NULL); |
|
202 |
if(th!=0) |
|
203 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
204 |
||
205 |
// can't make water of water! |
|
206 |
if (IS_TILETYPE(tile, MP_WATER)) { |
|
207 |
_error_message = STR_1007_ALREADY_BUILT; |
|
208 |
} else { |
|
209 |
||
210 |
/* is middle piece of a bridge? */ |
|
211 |
if (IS_TILETYPE(tile, MP_TUNNELBRIDGE) && _map5[tile] & 0x40) { /* build under bridge */ |
|
212 |
if(_map5[tile] & 0x20) { // transport route under bridge |
|
213 |
_error_message = STR_5800_OBJECT_IN_THE_WAY; |
|
214 |
ret = CMD_ERROR; |
|
215 |
} |
|
216 |
else if (_map5[tile] & 0x18) { // already water under bridge |
|
217 |
_error_message = STR_1007_ALREADY_BUILT; |
|
218 |
ret = CMD_ERROR; |
|
219 |
} |
|
220 |
||
221 |
/* no bridge? then try to clear it. */ |
|
222 |
} else { |
|
223 |
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
224 |
} |
|
225 |
if (ret == CMD_ERROR) return ret; |
|
226 |
cost += ret; |
|
227 |
||
228 |
/* execute modifications */ |
|
229 |
if (flags & DC_EXEC) { |
|
230 |
if(IS_TILETYPE(tile, MP_TUNNELBRIDGE)) { |
|
231 |
// change owner to OWNER_WATER and set land under bridge bit to water |
|
232 |
ModifyTile(tile, MP_MAP5 | MP_MAPOWNER, OWNER_WATER, _map5[tile] | 0x08); |
|
233 |
} else { |
|
234 |
ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0); |
|
235 |
} |
|
236 |
// mark the tiles around dirty too |
|
237 |
MarkTilesAroundDirty(tile); |
|
238 |
} |
|
239 |
||
240 |
cost += _price.clear_water; |
|
241 |
} |
|
242 |
if (tile == endtile) |
|
243 |
break; |
|
244 |
tile += delta; |
|
245 |
} |
|
246 |
if (cost == 0) return CMD_ERROR; |
|
247 |
||
248 |
return cost; |
|
249 |
} |
|
250 |
||
251 |
static int32 ClearTile_Water(uint tile, byte flags) { |
|
252 |
byte m5 = _map5[tile]; |
|
253 |
uint slope; |
|
254 |
||
255 |
if (m5 <= 1) { // water and shore |
|
256 |
// Allow building on water? It's ok to build on shores. |
|
257 |
if (flags & DC_NO_WATER && m5 != 1) |
|
258 |
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
|
259 |
||
260 |
// Make sure no vehicle is on the tile |
|
261 |
if (!EnsureNoVehicle(tile)) |
|
262 |
return CMD_ERROR; |
|
263 |
||
264 |
// Make sure it's not an edge tile. |
|
265 |
if (!(IS_INT_INSIDE(GET_TILE_X(tile),1,TILE_X_MAX-1) && |
|
266 |
IS_INT_INSIDE(GET_TILE_Y(tile),1,TILE_Y_MAX-1))) |
|
267 |
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP); |
|
268 |
||
269 |
if (m5 == 0) { |
|
270 |
if (flags & DC_EXEC) |
|
271 |
DoClearSquare(tile); |
|
272 |
return _price.clear_water; |
|
273 |
} else if (m5 == 1) { |
|
274 |
slope = GetTileSlope(tile,NULL); |
|
275 |
if (slope == 8 || slope == 4 || slope == 2 || slope == 1) { |
|
276 |
if (flags & DC_EXEC) |
|
277 |
DoClearSquare(tile); |
|
278 |
return _price.clear_water; |
|
279 |
} |
|
280 |
if (flags & DC_EXEC) |
|
281 |
DoClearSquare(tile); |
|
282 |
return _price.purchase_land; |
|
283 |
} else |
|
284 |
return CMD_ERROR; |
|
285 |
} else if ((m5 & 0x10) == 0x10) { |
|
286 |
// shiplift |
|
287 |
||
288 |
static const TileIndexDiff _shiplift_tomiddle_offs[12] = { |
|
289 |
0,0,0,0, // middle |
|
290 |
TILE_XY(-1, 0),TILE_XY(0, 1),TILE_XY(1, 0),TILE_XY(0, -1), // lower |
|
291 |
TILE_XY(1, 0),TILE_XY(0, -1),TILE_XY(-1, 0),TILE_XY(0, 1), // upper |
|
292 |
}; |
|
293 |
||
294 |
if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
295 |
// don't allow water to delete it. |
|
296 |
if (_current_player == OWNER_WATER) return CMD_ERROR; |
|
297 |
// move to the middle tile.. |
|
298 |
return RemoveShiplift(tile + _shiplift_tomiddle_offs[m5 & 0xF], flags); |
|
299 |
} else { |
|
300 |
// ship depot |
|
301 |
if (flags & DC_AUTO) |
|
302 |
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
303 |
||
304 |
if (m5 == 0x80 || m5 == 0x82) {} |
|
305 |
else if (m5 == 0x81) { tile -= TILE_XY(1,0); } |
|
306 |
else if (m5 == 0x83) { tile -= TILE_XY(0,1); } |
|
307 |
else |
|
308 |
return CMD_ERROR; |
|
309 |
||
310 |
return RemoveShipDepot(tile,flags); |
|
311 |
} |
|
312 |
} |
|
313 |
||
314 |
// return true if a tile is a water tile. |
|
315 |
static bool IsWateredTile(uint tile) |
|
316 |
{ |
|
317 |
byte m5 = _map5[tile]; |
|
318 |
if (IS_TILETYPE(tile, MP_WATER)) { |
|
319 |
return m5 != 1; |
|
320 |
} else if (IS_TILETYPE(tile, MP_STATION)) { |
|
321 |
// returns true if it is a dock-station (m5 inside values is m5<75 all stations, |
|
322 |
// 83<=m5<=114 new airports |
|
323 |
return !(m5 < 75 || (m5 >= 83 && m5 <= 114)); |
|
324 |
} else if (IS_TILETYPE(tile, MP_TUNNELBRIDGE)) { |
|
325 |
return (m5 & 0xF8) == 0xC8; |
|
326 |
} else |
|
327 |
return false; |
|
328 |
} |
|
329 |
||
330 |
// draw a canal styled water tile with dikes around |
|
331 |
void DrawCanalWater(uint tile) |
|
332 |
{ |
|
333 |
uint wa; |
|
334 |
||
335 |
// determine the edges around with water. |
|
336 |
wa = IsWateredTile(TILE_ADDXY(tile, -1, 0)) << 0; |
|
337 |
wa += IsWateredTile(TILE_ADDXY(tile, 0, 1)) << 1; |
|
338 |
wa += IsWateredTile(TILE_ADDXY(tile, 1, 0)) << 2; |
|
339 |
wa += IsWateredTile(TILE_ADDXY(tile, 0, -1)) << 3; |
|
340 |
||
341 |
if (!(wa & 1)) DrawGroundSprite(SPR_CANALS_BASE + 57); |
|
342 |
if (!(wa & 2)) DrawGroundSprite(SPR_CANALS_BASE + 58); |
|
343 |
if (!(wa & 4)) DrawGroundSprite(SPR_CANALS_BASE + 59); |
|
344 |
if (!(wa & 8)) DrawGroundSprite(SPR_CANALS_BASE + 60); |
|
345 |
||
346 |
// right corner |
|
347 |
if ((wa & 3) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 4); |
|
348 |
else if ((wa & 3) == 3 && !IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 8); |
|
349 |
||
350 |
// bottom corner |
|
351 |
if ((wa & 6) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 5); |
|
352 |
else if ((wa & 6) == 6 && !IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 9); |
|
353 |
||
354 |
// left corner |
|
355 |
if ((wa & 12) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 6); |
|
356 |
else if ((wa & 12) == 12 && !IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 10); |
|
357 |
||
358 |
// upper corner |
|
359 |
if ((wa & 9) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 7); |
|
360 |
else if ((wa & 9) == 9 && !IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 11); |
|
361 |
} |
|
362 |
||
363 |
typedef struct WaterDrawTileStruct { |
|
364 |
int8 delta_x; |
|
365 |
int8 delta_y; |
|
366 |
int8 delta_z; |
|
367 |
byte width; |
|
368 |
byte height; |
|
369 |
byte unk; |
|
370 |
SpriteID image; |
|
371 |
} WaterDrawTileStruct; |
|
372 |
||
373 |
typedef struct LocksDrawTileStruct { |
|
374 |
int8 delta_x, delta_y, delta_z; |
|
375 |
byte width, height, depth; |
|
376 |
SpriteID image; |
|
377 |
} LocksDrawTileStruct; |
|
378 |
||
379 |
#include "table/water_land.h" |
|
380 |
||
381 |
static void DrawWaterStuff(TileInfo *ti, const byte *t, uint32 palette, uint base) |
|
382 |
{ |
|
383 |
const WaterDrawTileStruct *wdts; |
|
384 |
uint32 image; |
|
385 |
||
386 |
DrawGroundSprite(*(uint16*)t); |
|
387 |
t += sizeof(uint16); |
|
388 |
||
389 |
for(wdts = (WaterDrawTileStruct *)t; (byte)wdts->delta_x != 0x80; wdts++) { |
|
390 |
image = wdts->image + base; |
|
391 |
if (_display_opt & DO_TRANS_BUILDINGS) { |
|
392 |
image |= palette; |
|
393 |
} else { |
|
394 |
image = (image & 0x3FFF) | 0x03224000; |
|
395 |
} |
|
396 |
AddSortableSpriteToDraw(image, ti->x + wdts->delta_x, ti->y + wdts->delta_y, wdts->width, wdts->height, wdts->unk, ti->z + wdts->delta_z); |
|
397 |
} |
|
398 |
} |
|
399 |
||
400 |
static void DrawTile_Water(TileInfo *ti) |
|
401 |
{ |
|
402 |
// draw water tile |
|
403 |
if (ti->map5 == 0) { |
|
404 |
DrawGroundSprite(0xFDD); |
|
405 |
if (ti->z != 0) DrawCanalWater(ti->tile); |
|
406 |
return; |
|
407 |
} |
|
408 |
||
409 |
// draw shore |
|
410 |
if (ti->map5 == 1) { |
|
411 |
assert(ti->tileh < 16); |
|
412 |
DrawGroundSprite(_water_shore_sprites[ti->tileh]); |
|
413 |
return; |
|
414 |
} |
|
415 |
||
416 |
// draw shiplift |
|
417 |
if ((ti->map5 & 0xF0) == 0x10) { |
|
418 |
const byte *t = _shiplift_display_seq[ti->map5 & 0xF]; |
|
419 |
DrawWaterStuff(ti, t, 0, ti->z > t[19] ? 24 : 0); |
|
420 |
return; |
|
421 |
} |
|
422 |
||
423 |
DrawWaterStuff(ti, _shipdepot_display_seq[ti->map5 & 0x7F], PLAYER_SPRITE_COLOR(_map_owner[ti->tile]), 0); |
|
424 |
} |
|
425 |
||
426 |
void DrawShipDepotSprite(int x, int y, int image) |
|
427 |
{ |
|
428 |
const byte *t; |
|
429 |
const WaterDrawTileStruct *wdts; |
|
430 |
||
431 |
t = _shipdepot_display_seq[image]; |
|
432 |
DrawSprite(*(uint16*)t, x, y); |
|
433 |
t += sizeof(uint16); |
|
434 |
||
435 |
for(wdts = (WaterDrawTileStruct *)t; (byte)wdts->delta_x != 0x80; wdts++) { |
|
436 |
Point pt = RemapCoords(wdts->delta_x, wdts->delta_y, wdts->delta_z); |
|
437 |
DrawSprite(wdts->image + PLAYER_SPRITE_COLOR(_local_player), x + pt.x, y + pt.y); |
|
438 |
} |
|
439 |
} |
|
440 |
||
441 |
||
442 |
uint GetSlopeZ_Water(TileInfo *ti) |
|
443 |
{ |
|
444 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z; |
|
445 |
} |
|
446 |
||
39 | 447 |
uint GetSlopeTileh_Water(TileInfo *ti) |
448 |
{ |
|
449 |
return ti->tileh; |
|
450 |
} |
|
451 |
||
0 | 452 |
static void GetAcceptedCargo_Water(uint tile, AcceptedCargo *ac) |
453 |
{ |
|
454 |
/* not used */ |
|
455 |
} |
|
456 |
||
457 |
static void GetTileDesc_Water(uint tile, TileDesc *td) |
|
458 |
{ |
|
459 |
if (_map5[tile] == 0 && GET_TILEHEIGHT(tile) == 0) |
|
460 |
td->str = STR_3804_WATER; |
|
461 |
else if (_map5[tile] == 0) |
|
462 |
td->str = STR_LANDINFO_CANAL; |
|
463 |
else if (_map5[tile] == 1) |
|
464 |
td->str = STR_3805_COAST_OR_RIVERBANK; |
|
465 |
else if ((_map5[tile]&0xF0) == 0x10) |
|
466 |
td->str = STR_LANDINFO_LOCK; |
|
467 |
else |
|
468 |
td->str = STR_3806_SHIP_DEPOT; |
|
469 |
||
470 |
td->owner = _map_owner[tile]; |
|
471 |
} |
|
472 |
||
473 |
static void AnimateTile_Water(uint tile) |
|
474 |
{ |
|
475 |
/* not used */ |
|
476 |
} |
|
477 |
||
478 |
static void TileLoopWaterHelper(uint tile, const int16 *offs) |
|
479 |
{ |
|
480 |
byte *p; |
|
481 |
||
482 |
p = &_map_type_and_height[tile]; |
|
483 |
tile += offs[0]; |
|
484 |
||
485 |
// type of this tile mustn't be water already. |
|
486 |
if (p[offs[0]] >> 4 == MP_WATER) |
|
487 |
return; |
|
488 |
||
489 |
if ( (p[offs[1]] | p[offs[2]]) & 0xF ) |
|
490 |
return; |
|
491 |
||
492 |
if ( (p[offs[3]] | p[offs[4]]) & 0xF ) { |
|
493 |
// make coast.. |
|
494 |
if (p[offs[0]] >> 4 == MP_CLEAR || p[offs[0]] >> 4 == MP_TREES) { |
|
495 |
_current_player = OWNER_WATER; |
|
496 |
if (DoCommandByTile(tile,0,0,DC_EXEC | DC_AUTO, CMD_LANDSCAPE_CLEAR) != CMD_ERROR) |
|
497 |
ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR,OWNER_WATER,1); |
|
498 |
} |
|
499 |
} else { |
|
500 |
if (IS_TILETYPE(tile, MP_TUNNELBRIDGE)) { |
|
501 |
byte m5 = _map5[tile]; |
|
502 |
if ( (m5&0xF8) == 0xC8 || (m5&0xF8) == 0xF0) |
|
503 |
return; |
|
504 |
||
505 |
if ( (m5&0xC0) == 0xC0) { |
|
506 |
ModifyTile(tile, MP_MAPOWNER | MP_MAP5,OWNER_WATER,(m5 & ~0x38)|0x8); |
|
507 |
return; |
|
508 |
} |
|
509 |
} |
|
510 |
||
511 |
_current_player = OWNER_WATER; |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
512 |
{ |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
513 |
Vehicle *v = FindVehicleBetween(tile, tile, 0); |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
514 |
if (v != NULL) {FloodVehicle(v);} |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
515 |
} |
0 | 516 |
if (DoCommandByTile(tile,0,0,DC_EXEC, CMD_LANDSCAPE_CLEAR) != CMD_ERROR) |
517 |
ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR,OWNER_WATER,0); |
|
518 |
} |
|
519 |
} |
|
520 |
||
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
521 |
static void FloodVehicle(Vehicle *v) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
522 |
{ |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
523 |
Vehicle *u; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
524 |
uint16 pass; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
525 |
if (!(v->vehstatus & VS_CRASHED)) { |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
526 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
527 |
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
|
528 |
pass = 1; // driver |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
529 |
if (v->cargo_type == CT_PASSENGERS) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
530 |
pass += v->cargo_count; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
531 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
532 |
v->vehstatus |= VS_CRASHED; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
533 |
v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
534 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
535 |
} |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
536 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
537 |
else if (v->type == VEH_Train) { |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
538 |
v = GetFirstVehicleInChain(v); |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
539 |
u = v; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
540 |
pass = 4; // driver |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
541 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
542 |
// crash all wagons, and count passangers |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
543 |
BEGIN_ENUM_WAGONS(v) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
544 |
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
|
545 |
v->vehstatus |= VS_CRASHED; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
546 |
END_ENUM_WAGONS(v) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
547 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
548 |
v = u; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
549 |
v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
550 |
InvalidateWindow(WC_TRAINS_LIST, v->owner); |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
551 |
} |
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 |
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
|
554 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
555 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
556 |
SET_DPARAM16(0, pass); |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
557 |
AddNewsItem(STR_B006_FLOOD_VEHICLE_DESTROYED, |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
558 |
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
|
559 |
v->index, |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
560 |
0); |
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 |
CreateEffectVehicleRel(v,4,4,8,EV_CRASHED_SMOKE); // show cool destruction effects |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
563 |
SndPlayVehicleFx(16, v); // create sound |
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 |
|
0 | 566 |
// called from tunnelbridge_cmd |
567 |
void TileLoop_Water(uint tile) |
|
568 |
{ |
|
569 |
int i; |
|
570 |
static const TileIndexDiff _tile_loop_offs_array[4][5] = { |
|
571 |
// tile to mod shore? shore? |
|
572 |
{TILE_XY(-1,0), TILE_XY(0,0), TILE_XY(0,1), TILE_XY(-1,0), TILE_XY(-1,1)}, |
|
573 |
{TILE_XY(0,1), TILE_XY(0,1), TILE_XY(1,1), TILE_XY(0,2), TILE_XY(1,2)}, |
|
574 |
{TILE_XY(1,0), TILE_XY(1,0), TILE_XY(1,1), TILE_XY(2,0), TILE_XY(2,1)}, |
|
575 |
{TILE_XY(0,-1), TILE_XY(0,0), TILE_XY(1,0), TILE_XY(0,-1), TILE_XY(1,-1)}, |
|
576 |
}; |
|
577 |
||
578 |
if ( IS_INT_INSIDE(GET_TILE_X(tile),1,TILES_X-3+1) && |
|
579 |
IS_INT_INSIDE(GET_TILE_Y(tile),1,TILES_Y-3+1)) { |
|
580 |
for(i=0; i!=4; i++) |
|
581 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[i]); |
|
582 |
} |
|
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
583 |
|
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
584 |
// edges |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
585 |
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
|
586 |
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
|
587 |
|
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
588 |
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
|
589 |
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
|
590 |
|
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
591 |
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
|
592 |
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
|
593 |
|
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
594 |
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
|
595 |
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
|
596 |
|
0 | 597 |
} |
598 |
||
599 |
||
600 |
static const byte _coast_tracks[16] = {0, 32, 4, 0, 16, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0}; |
|
601 |
static const byte _shipdepot_tracks[4] = {1,1,2,2}; |
|
602 |
static const byte _shiplift_tracks[12] = {1,2,1,2,1,2,1,2,1,2,1,2}; |
|
603 |
static uint32 GetTileTrackStatus_Water(uint tile, int mode) |
|
604 |
{ |
|
605 |
uint m5; |
|
606 |
uint b; |
|
607 |
||
608 |
if (mode != 4) |
|
609 |
return 0; |
|
610 |
||
611 |
m5 = _map5[tile]; |
|
612 |
if (m5 == 0) |
|
613 |
return 0x3F3F; |
|
614 |
||
615 |
if (m5 == 1) { |
|
616 |
b = _coast_tracks[GetTileSlope(tile, NULL)&0xF]; |
|
617 |
return b + (b<<8); |
|
618 |
} |
|
619 |
||
620 |
if ( (m5 & 0x10) == 0x10) { |
|
621 |
// |
|
622 |
b = _shiplift_tracks[m5 & 0xF]; |
|
623 |
return b + (b<<8); |
|
624 |
} |
|
625 |
||
626 |
if (!(m5 & 0x80)) |
|
627 |
return 0; |
|
628 |
||
629 |
b = _shipdepot_tracks[m5 & 0x7F]; |
|
630 |
return b + (b<<8); |
|
631 |
} |
|
632 |
||
633 |
extern void ShowShipDepotWindow(uint tile); |
|
634 |
||
635 |
static void ClickTile_Water(uint tile) |
|
636 |
{ |
|
637 |
byte m5 = _map5[tile] - 0x80; |
|
638 |
||
639 |
if (IS_BYTE_INSIDE(m5, 0, 3+1)) { |
|
640 |
if (m5 & 1) |
|
641 |
tile += (m5==1) ? TILE_XY(-1,0) : TILE_XY(0,-1); |
|
642 |
ShowShipDepotWindow(tile); |
|
643 |
} |
|
644 |
} |
|
645 |
||
646 |
static void ChangeTileOwner_Water(uint tile, byte old_player, byte new_player) |
|
647 |
{ |
|
648 |
if (_map_owner[tile] != old_player) |
|
649 |
return; |
|
650 |
||
651 |
if (new_player != 255) { |
|
652 |
_map_owner[tile] = new_player; |
|
653 |
} else { |
|
654 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
655 |
} |
|
656 |
} |
|
657 |
||
658 |
static uint32 VehicleEnter_Water(Vehicle *v, uint tile, int x, int y) |
|
659 |
{ |
|
660 |
return 0; |
|
661 |
} |
|
662 |
||
663 |
void InitializeDock() |
|
664 |
{ |
|
665 |
_last_built_ship_depot_tile = 0; |
|
666 |
} |
|
667 |
||
668 |
const TileTypeProcs _tile_type_water_procs = { |
|
669 |
DrawTile_Water, /* draw_tile_proc */ |
|
670 |
GetSlopeZ_Water, /* get_slope_z_proc */ |
|
671 |
ClearTile_Water, /* clear_tile_proc */ |
|
672 |
GetAcceptedCargo_Water, /* get_accepted_cargo_proc */ |
|
673 |
GetTileDesc_Water, /* get_tile_desc_proc */ |
|
674 |
GetTileTrackStatus_Water, /* get_tile_track_status_proc */ |
|
675 |
ClickTile_Water, /* click_tile_proc */ |
|
676 |
AnimateTile_Water, /* animate_tile_proc */ |
|
677 |
TileLoop_Water, /* tile_loop_clear */ |
|
678 |
ChangeTileOwner_Water, /* change_tile_owner_clear */ |
|
679 |
NULL, /* get_produced_cargo_proc */ |
|
680 |
VehicleEnter_Water, /* vehicle_enter_tile_proc */ |
|
681 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 682 |
GetSlopeTileh_Water, /* get_slope_tileh_proc */ |
0 | 683 |
}; |
684 |