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