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