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