author | peter1138 |
Fri, 28 Apr 2006 21:32:59 +0000 | |
changeset 3688 | fa1326dee4e3 |
parent 3657 | eb28d97d3d18 |
child 3884 | 793081f80381 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1796
diff
changeset
|
4 |
#include "openttd.h" |
3189
bf047128dee7
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3183
diff
changeset
|
5 |
#include "bridge_map.h" |
3338
7cff208f0446
(svn r4120) Use the new station functions where appropriate
tron
parents:
3275
diff
changeset
|
6 |
#include "station_map.h" |
1363
775a7ee52369
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1359
diff
changeset
|
7 |
#include "table/sprites.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
8 |
#include "table/strings.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
9 |
#include "functions.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
588
diff
changeset
|
10 |
#include "map.h" |
1209
2e00193652b2
(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
|
11 |
#include "tile.h" |
0 | 12 |
#include "vehicle.h" |
13 |
#include "viewport.h" |
|
14 |
#include "command.h" |
|
15 |
#include "town.h" |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
16 |
#include "news.h" |
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
314
diff
changeset
|
17 |
#include "sound.h" |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
18 |
#include "depot.h" |
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1632
diff
changeset
|
19 |
#include "vehicle_gui.h" |
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2657
diff
changeset
|
20 |
#include "train.h" |
3111
750f37699a13
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
21 |
#include "water_map.h" |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
22 |
|
2261
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2186
diff
changeset
|
23 |
const SpriteID _water_shore_sprites[15] = { |
2517
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2502
diff
changeset
|
24 |
0, |
6e3832ddd0f6
(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_1, |
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2502
diff
changeset
|
26 |
SPR_SHORE_TILEH_2, |
6e3832ddd0f6
(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_3, |
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2502
diff
changeset
|
28 |
SPR_SHORE_TILEH_4, |
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2502
diff
changeset
|
29 |
0, |
6e3832ddd0f6
(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_6, |
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2502
diff
changeset
|
31 |
0, |
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2502
diff
changeset
|
32 |
SPR_SHORE_TILEH_8, |
6e3832ddd0f6
(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_9, |
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2502
diff
changeset
|
34 |
0, |
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2502
diff
changeset
|
35 |
0, |
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2502
diff
changeset
|
36 |
SPR_SHORE_TILEH_12, |
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2502
diff
changeset
|
37 |
0, |
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2502
diff
changeset
|
38 |
0 |
2261
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2186
diff
changeset
|
39 |
}; |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2186
diff
changeset
|
40 |
|
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2186
diff
changeset
|
41 |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
42 |
static void FloodVehicle(Vehicle *v); |
0 | 43 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1752
diff
changeset
|
44 |
/** Build a ship depot. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
45 |
* @param tile tile where ship depot is built |
2657
c418f625b2fd
(svn r3199) -Fix: There are only 2 possible directions for ship depots, not 4
tron
parents:
2652
diff
changeset
|
46 |
* @param p1 depot direction (0 == X or 1 == Y) |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1752
diff
changeset
|
47 |
* @param p2 unused |
0 | 48 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
49 |
int32 CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 50 |
{ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
51 |
TileIndex tile2; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
52 |
|
0 | 53 |
int32 cost, ret; |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
54 |
Depot *depot; |
0 | 55 |
|
56 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
57 |
||
2657
c418f625b2fd
(svn r3199) -Fix: There are only 2 possible directions for ship depots, not 4
tron
parents:
2652
diff
changeset
|
58 |
if (p1 > 1) return CMD_ERROR; |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1752
diff
changeset
|
59 |
|
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1752
diff
changeset
|
60 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 61 |
|
1981 | 62 |
tile2 = tile + (p1 ? TileDiffXY(0, 1) : TileDiffXY(1, 0)); |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1752
diff
changeset
|
63 |
if (!EnsureNoVehicle(tile2)) return CMD_ERROR; |
0 | 64 |
|
65 |
if (!IsClearWaterTile(tile) || !IsClearWaterTile(tile2)) |
|
66 |
return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER); |
|
67 |
||
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
68 |
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1752
diff
changeset
|
69 |
if (CmdFailed(ret)) return CMD_ERROR; |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
70 |
ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1752
diff
changeset
|
71 |
if (CmdFailed(ret)) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
72 |
|
0 | 73 |
// pretend that we're not making land from the water even though we actually are. |
74 |
cost = 0; |
|
75 |
||
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
76 |
depot = AllocateDepot(); |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1752
diff
changeset
|
77 |
if (depot == NULL) return CMD_ERROR; |
0 | 78 |
|
79 |
if (flags & DC_EXEC) { |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
80 |
depot->xy = tile; |
0 | 81 |
_last_built_ship_depot_tile = tile; |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
82 |
depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
0 | 83 |
|
3372
f6afa98d5219
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents:
3338
diff
changeset
|
84 |
MakeShipDepot(tile,_current_player, DEPOT_NORTH, p1); |
f6afa98d5219
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents:
3338
diff
changeset
|
85 |
MakeShipDepot(tile2,_current_player, DEPOT_SOUTH, p1); |
f6afa98d5219
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents:
3338
diff
changeset
|
86 |
MarkTileDirtyByTile(tile); |
f6afa98d5219
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents:
3338
diff
changeset
|
87 |
MarkTileDirtyByTile(tile2); |
0 | 88 |
} |
89 |
||
90 |
return cost + _price.build_ship_depot; |
|
91 |
} |
|
92 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
93 |
static int32 RemoveShipDepot(TileIndex tile, uint32 flags) |
0 | 94 |
{ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
95 |
TileIndex tile2; |
0 | 96 |
|
3373
2838aadd3a28
(svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents:
3372
diff
changeset
|
97 |
if (!IsShipDepot(tile)) return CMD_ERROR; |
2951 | 98 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
99 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
|
0 | 100 |
|
3373
2838aadd3a28
(svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents:
3372
diff
changeset
|
101 |
tile2 = GetOtherShipDepotTile(tile); |
0 | 102 |
|
2951 | 103 |
if (!EnsureNoVehicle(tile2)) return CMD_ERROR; |
0 | 104 |
|
105 |
if (flags & DC_EXEC) { |
|
3373
2838aadd3a28
(svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents:
3372
diff
changeset
|
106 |
/* Kill the depot, which is registered at the northernmost tile. Use that one */ |
2838aadd3a28
(svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents:
3372
diff
changeset
|
107 |
DoDeleteDepot(tile2 < tile ? tile2 : tile); |
0 | 108 |
|
3111
750f37699a13
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
109 |
MakeWater(tile); |
750f37699a13
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
110 |
MakeWater(tile2); |
750f37699a13
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
111 |
MarkTileDirtyByTile(tile); |
750f37699a13
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
112 |
MarkTileDirtyByTile(tile2); |
0 | 113 |
} |
114 |
||
115 |
return _price.remove_ship_depot; |
|
116 |
} |
|
117 |
||
118 |
// build a shiplift |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3111
diff
changeset
|
119 |
static int32 DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags) |
0 | 120 |
{ |
121 |
int32 ret; |
|
122 |
int delta; |
|
123 |
||
124 |
// middle tile |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
125 |
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
2737
fb1556b8f5e0
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2676
diff
changeset
|
126 |
if (CmdFailed(ret)) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
127 |
|
900 | 128 |
delta = TileOffsByDir(dir); |
0 | 129 |
// lower tile |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
130 |
ret = DoCommand(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
2737
fb1556b8f5e0
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2676
diff
changeset
|
131 |
if (CmdFailed(ret)) return CMD_ERROR; |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
132 |
if (GetTileSlope(tile - delta, NULL) != SLOPE_FLAT) { |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
133 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
134 |
} |
0 | 135 |
|
136 |
// upper tile |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
137 |
ret = DoCommand(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
2737
fb1556b8f5e0
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2676
diff
changeset
|
138 |
if (CmdFailed(ret)) return CMD_ERROR; |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
139 |
if (GetTileSlope(tile + delta, NULL) != SLOPE_FLAT) { |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
140 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
141 |
} |
0 | 142 |
|
143 |
if (flags & DC_EXEC) { |
|
3372
f6afa98d5219
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents:
3338
diff
changeset
|
144 |
MakeLock(tile, dir); |
f6afa98d5219
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents:
3338
diff
changeset
|
145 |
MarkTileDirtyByTile(tile); |
f6afa98d5219
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents:
3338
diff
changeset
|
146 |
MarkTileDirtyByTile(tile - delta); |
f6afa98d5219
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents:
3338
diff
changeset
|
147 |
MarkTileDirtyByTile(tile + delta); |
0 | 148 |
} |
149 |
||
150 |
return _price.clear_water * 22 >> 3; |
|
151 |
} |
|
152 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
153 |
static int32 RemoveShiplift(TileIndex tile, uint32 flags) |
0 | 154 |
{ |
3373
2838aadd3a28
(svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents:
3372
diff
changeset
|
155 |
TileIndexDiff delta = TileOffsByDir(GetLockDirection(tile)); |
0 | 156 |
|
157 |
// make sure no vehicle is on the tile. |
|
158 |
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(tile + delta) || !EnsureNoVehicle(tile - delta)) |
|
159 |
return CMD_ERROR; |
|
160 |
||
161 |
if (flags & DC_EXEC) { |
|
162 |
DoClearSquare(tile); |
|
163 |
DoClearSquare(tile + delta); |
|
164 |
DoClearSquare(tile - delta); |
|
165 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
166 |
|
0 | 167 |
return _price.clear_water * 2; |
168 |
} |
|
169 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
170 |
static void MarkTilesAroundDirty(TileIndex tile) |
0 | 171 |
{ |
172 |
MarkTileDirtyByTile(TILE_ADDXY(tile, 0, 1)); |
|
173 |
MarkTileDirtyByTile(TILE_ADDXY(tile, 0, -1)); |
|
174 |
MarkTileDirtyByTile(TILE_ADDXY(tile, 1, 0)); |
|
175 |
MarkTileDirtyByTile(TILE_ADDXY(tile, -1, 0)); |
|
176 |
} |
|
177 |
||
1796
614d996f6be7
(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 |
/** Builds a lock (ship-lift) |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
179 |
* @param tile tile where to place the lock |
1796
614d996f6be7
(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 |
* @param p1 unused |
614d996f6be7
(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 |
* @param p2 unused |
614d996f6be7
(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
|
182 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
183 |
int32 CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 184 |
{ |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3111
diff
changeset
|
185 |
DiagDirection dir; |
889
64d2f7d5f02b
(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
|
186 |
|
64d2f7d5f02b
(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
|
187 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
0 | 188 |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3111
diff
changeset
|
189 |
switch (GetTileSlope(tile, NULL)) { |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
190 |
case SLOPE_SW: dir = DIAGDIR_SW; break; |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
191 |
case SLOPE_SE: dir = DIAGDIR_SE; break; |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
192 |
case SLOPE_NW: dir = DIAGDIR_NW; break; |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
193 |
case SLOPE_NE: dir = DIAGDIR_NE; break; |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3111
diff
changeset
|
194 |
default: return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
1796
614d996f6be7
(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 |
} |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3111
diff
changeset
|
196 |
return DoBuildShiplift(tile, dir, flags); |
0 | 197 |
} |
198 |
||
1796
614d996f6be7
(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 |
/** Build a piece of canal. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
200 |
* @param tile end tile of stretch-dragging |
1796
614d996f6be7
(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 |
* @param p1 start tile of stretch-dragging |
614d996f6be7
(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 |
* @param p2 unused |
614d996f6be7
(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 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
204 |
int32 CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 205 |
{ |
3177 | 206 |
int32 cost; |
1632
10c391e108b7
(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 |
int size_x, size_y; |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
208 |
int x; |
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
209 |
int y; |
1796
614d996f6be7
(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 |
int sx, sy; |
614d996f6be7
(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 |
|
2934
3f29a7212713
(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
|
212 |
if (p1 >= MapSize()) return CMD_ERROR; |
1796
614d996f6be7
(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
|
213 |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
214 |
x = TileX(tile); |
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
215 |
y = TileY(tile); |
1796
614d996f6be7
(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 |
sx = TileX(p1); |
614d996f6be7
(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 |
sy = TileY(p1); |
1632
10c391e108b7
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
Darkvater
parents:
1605
diff
changeset
|
218 |
|
0 | 219 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
220 |
||
1632
10c391e108b7
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
Darkvater
parents:
1605
diff
changeset
|
221 |
if (x < sx) intswap(x, sx); |
10c391e108b7
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
Darkvater
parents:
1605
diff
changeset
|
222 |
if (y < sy) intswap(y, sy); |
10c391e108b7
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
Darkvater
parents:
1605
diff
changeset
|
223 |
size_x = (x - sx) + 1; |
10c391e108b7
(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 |
size_y = (y - sy) + 1; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
225 |
|
1796
614d996f6be7
(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 |
/* Outside the editor you can only drag canals, and not areas */ |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1784
diff
changeset
|
227 |
if (_game_mode != GM_EDITOR && (sx != x && sy != y)) return CMD_ERROR; |
614d996f6be7
(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 |
|
0 | 229 |
cost = 0; |
1981 | 230 |
BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) { |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
231 |
if (GetTileSlope(tile, NULL) != SLOPE_FLAT) { |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
232 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
233 |
} |
0 | 234 |
|
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
235 |
// can't make water of water! |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
236 |
if (IsTileType(tile, MP_WATER)) continue; |
1632
10c391e108b7
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
Darkvater
parents:
1605
diff
changeset
|
237 |
|
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
238 |
/* is middle piece of a bridge? */ |
3234
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3189
diff
changeset
|
239 |
if (IsBridgeTile(tile) && IsBridgeMiddle(tile)) { |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3189
diff
changeset
|
240 |
if (IsTransportUnderBridge(tile)) { |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
241 |
return_cmd_error(STR_5800_OBJECT_IN_THE_WAY); |
3234
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3189
diff
changeset
|
242 |
} |
3177 | 243 |
|
3234
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3189
diff
changeset
|
244 |
if (IsWaterUnderBridge(tile)) return_cmd_error(STR_1007_ALREADY_BUILT); |
3177 | 245 |
|
3189
bf047128dee7
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3183
diff
changeset
|
246 |
if (flags & DC_EXEC) SetWaterUnderBridge(tile); |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
247 |
} else { |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
248 |
/* no bridge, try to clear it. */ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
249 |
int32 ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
0 | 250 |
|
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
251 |
if (CmdFailed(ret)) return ret; |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
252 |
cost += ret; |
3177 | 253 |
|
3189
bf047128dee7
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3183
diff
changeset
|
254 |
if (flags & DC_EXEC) MakeWater(tile); |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
255 |
} |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
256 |
|
3189
bf047128dee7
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3183
diff
changeset
|
257 |
if (flags & DC_EXEC) { |
bf047128dee7
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3183
diff
changeset
|
258 |
MarkTileDirtyByTile(tile); |
bf047128dee7
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3183
diff
changeset
|
259 |
MarkTilesAroundDirty(tile); |
bf047128dee7
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3183
diff
changeset
|
260 |
} |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
261 |
|
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
262 |
cost += _price.clear_water; |
1632
10c391e108b7
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
Darkvater
parents:
1605
diff
changeset
|
263 |
} END_TILE_LOOP(tile, size_x, size_y, 0); |
0 | 264 |
|
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
265 |
if (cost == 0) { |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
266 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
267 |
} else { |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
268 |
return cost; |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
269 |
} |
0 | 270 |
} |
271 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
272 |
static int32 ClearTile_Water(TileIndex tile, byte flags) |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
273 |
{ |
3425
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
274 |
switch (GetWaterTileType(tile)) { |
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
275 |
case WATER_CLEAR: |
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
276 |
if (flags & DC_NO_WATER) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
0 | 277 |
|
3425
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
278 |
// Make sure no vehicle is on the tile |
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
279 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 280 |
|
3425
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
281 |
// Make sure it's not an edge tile. |
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
282 |
if (!IS_INT_INSIDE(TileX(tile), 1, MapMaxX() - 1) || |
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
283 |
!IS_INT_INSIDE(TileY(tile), 1, MapMaxY() - 1)) { |
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
284 |
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP); |
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
285 |
} |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
286 |
|
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
287 |
if (flags & DC_EXEC) DoClearSquare(tile); |
3425
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
288 |
return _price.clear_water; |
0 | 289 |
|
3439 | 290 |
case WATER_COAST: { |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
291 |
Slope slope = GetTileSlope(tile, NULL); |
3439 | 292 |
|
293 |
// Make sure no vehicle is on the tile |
|
294 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
|
295 |
||
296 |
// Make sure it's not an edge tile. |
|
297 |
if (!IS_INT_INSIDE(TileX(tile), 1, MapMaxX() - 1) || |
|
298 |
!IS_INT_INSIDE(TileY(tile), 1, MapMaxY() - 1)) { |
|
299 |
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP); |
|
3425
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
300 |
} |
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
301 |
|
3439 | 302 |
if (flags & DC_EXEC) DoClearSquare(tile); |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
303 |
if (slope == SLOPE_N || slope == SLOPE_E || slope == SLOPE_S || slope == SLOPE_W) { |
3439 | 304 |
return _price.clear_water; |
305 |
} else { |
|
306 |
return _price.purchase_land; |
|
3425
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
307 |
} |
3439 | 308 |
} |
309 |
||
310 |
case WATER_LOCK: { |
|
311 |
static const TileIndexDiffC _shiplift_tomiddle_offs[] = { |
|
312 |
{ 0, 0}, {0, 0}, { 0, 0}, {0, 0}, // middle |
|
313 |
{-1, 0}, {0, 1}, { 1, 0}, {0, -1}, // lower |
|
314 |
{ 1, 0}, {0, -1}, {-1, 0}, {0, 1}, // upper |
|
315 |
}; |
|
316 |
||
317 |
if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
318 |
if (_current_player == OWNER_WATER) return CMD_ERROR; |
|
319 |
// move to the middle tile.. |
|
320 |
return RemoveShiplift(tile + ToTileIndexDiff(_shiplift_tomiddle_offs[GetSection(tile)]), flags); |
|
321 |
} |
|
322 |
||
3425
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
323 |
case WATER_DEPOT: |
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
324 |
if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
325 |
|
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
326 |
return RemoveShipDepot(tile, flags); |
3439 | 327 |
|
328 |
default: |
|
329 |
NOT_REACHED(); |
|
330 |
return 0; |
|
0 | 331 |
} |
332 |
} |
|
333 |
||
334 |
// return true if a tile is a water tile. |
|
1048 | 335 |
static bool IsWateredTile(TileIndex tile) |
0 | 336 |
{ |
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
337 |
switch (GetTileType(tile)) { |
1048 | 338 |
case MP_WATER: |
3423
dab85d82708b
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
339 |
return !IsCoast(tile); |
1048 | 340 |
|
341 |
case MP_STATION: |
|
3338
7cff208f0446
(svn r4120) Use the new station functions where appropriate
tron
parents:
3275
diff
changeset
|
342 |
return IsOilRig(tile) || IsDock(tile) || IsBuoy_(tile); |
1048 | 343 |
|
344 |
case MP_TUNNELBRIDGE: |
|
3234
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3189
diff
changeset
|
345 |
return IsBridge(tile) && IsBridgeMiddle(tile) && IsWaterUnderBridge(tile); |
1048 | 346 |
|
347 |
default: |
|
348 |
return false; |
|
349 |
} |
|
0 | 350 |
} |
351 |
||
352 |
// draw a canal styled water tile with dikes around |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
353 |
void DrawCanalWater(TileIndex tile) |
0 | 354 |
{ |
355 |
uint wa; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
356 |
|
0 | 357 |
// determine the edges around with water. |
358 |
wa = IsWateredTile(TILE_ADDXY(tile, -1, 0)) << 0; |
|
359 |
wa += IsWateredTile(TILE_ADDXY(tile, 0, 1)) << 1; |
|
360 |
wa += IsWateredTile(TILE_ADDXY(tile, 1, 0)) << 2; |
|
361 |
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
|
362 |
|
0 | 363 |
if (!(wa & 1)) DrawGroundSprite(SPR_CANALS_BASE + 57); |
364 |
if (!(wa & 2)) DrawGroundSprite(SPR_CANALS_BASE + 58); |
|
365 |
if (!(wa & 4)) DrawGroundSprite(SPR_CANALS_BASE + 59); |
|
366 |
if (!(wa & 8)) DrawGroundSprite(SPR_CANALS_BASE + 60); |
|
367 |
||
368 |
// right corner |
|
2989 | 369 |
switch (wa & 0x03) { |
370 |
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 4); break; |
|
371 |
case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 8); break; |
|
372 |
} |
|
0 | 373 |
|
374 |
// bottom corner |
|
2989 | 375 |
switch (wa & 0x06) { |
376 |
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 5); break; |
|
377 |
case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 9); break; |
|
378 |
} |
|
0 | 379 |
|
380 |
// left corner |
|
2989 | 381 |
switch (wa & 0x0C) { |
382 |
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 6); break; |
|
383 |
case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 10); break; |
|
384 |
} |
|
0 | 385 |
|
386 |
// upper corner |
|
2989 | 387 |
switch (wa & 0x09) { |
388 |
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 7); break; |
|
389 |
case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 11); break; |
|
390 |
} |
|
0 | 391 |
} |
392 |
||
393 |
typedef struct LocksDrawTileStruct { |
|
394 |
int8 delta_x, delta_y, delta_z; |
|
395 |
byte width, height, depth; |
|
396 |
SpriteID image; |
|
397 |
} LocksDrawTileStruct; |
|
398 |
||
399 |
#include "table/water_land.h" |
|
400 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2261
diff
changeset
|
401 |
static void DrawWaterStuff(const TileInfo *ti, const WaterDrawTileStruct *wdts, |
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
402 |
uint32 palette, uint base |
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
403 |
) |
0 | 404 |
{ |
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
405 |
DrawGroundSprite(wdts++->image); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
406 |
|
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
407 |
for (; wdts->delta_x != 0x80; wdts++) { |
2989 | 408 |
uint32 image = wdts->image + base; |
0 | 409 |
if (_display_opt & DO_TRANS_BUILDINGS) { |
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2049
diff
changeset
|
410 |
MAKE_TRANSPARENT(image); |
497
4d1c889526ee
(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
|
411 |
} else { |
0 | 412 |
image |= palette; |
413 |
} |
|
414 |
AddSortableSpriteToDraw(image, ti->x + wdts->delta_x, ti->y + wdts->delta_y, wdts->width, wdts->height, wdts->unk, ti->z + wdts->delta_z); |
|
415 |
} |
|
416 |
} |
|
417 |
||
418 |
static void DrawTile_Water(TileInfo *ti) |
|
419 |
{ |
|
3402
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
420 |
switch (GetWaterTileType(ti->tile)) { |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
421 |
case WATER_CLEAR: |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
422 |
DrawGroundSprite(SPR_FLAT_WATER_TILE); |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
423 |
if (ti->z != 0) DrawCanalWater(ti->tile); |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
424 |
break; |
0 | 425 |
|
3402
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
426 |
case WATER_COAST: |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
427 |
assert(!IsSteepSlope(ti->tileh)); |
3402
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
428 |
DrawGroundSprite(_water_shore_sprites[ti->tileh]); |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
429 |
break; |
0 | 430 |
|
3402
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
431 |
case WATER_LOCK: { |
3425
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
432 |
const WaterDrawTileStruct *t = _shiplift_display_seq[GetSection(ti->tile)]; |
3402
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
433 |
DrawWaterStuff(ti, t, 0, ti->z > t[3].delta_y ? 24 : 0); |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
434 |
} break; |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
435 |
|
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
436 |
case WATER_DEPOT: |
3425
5411e9c8b6c8
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
437 |
DrawWaterStuff(ti, _shipdepot_display_seq[GetSection(ti->tile)], PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), 0); |
3402
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
438 |
break; |
0 | 439 |
} |
440 |
} |
|
441 |
||
442 |
void DrawShipDepotSprite(int x, int y, int image) |
|
443 |
{ |
|
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
444 |
const WaterDrawTileStruct *wdts = _shipdepot_display_seq[image]; |
0 | 445 |
|
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
446 |
DrawSprite(wdts++->image, x, y); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
447 |
|
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
448 |
for (; wdts->delta_x != 0x80; wdts++) { |
0 | 449 |
Point pt = RemapCoords(wdts->delta_x, wdts->delta_y, wdts->delta_z); |
450 |
DrawSprite(wdts->image + PLAYER_SPRITE_COLOR(_local_player), x + pt.x, y + pt.y); |
|
451 |
} |
|
452 |
} |
|
453 |
||
454 |
||
2537 | 455 |
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
|
456 |
{ |
2537 | 457 |
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z; |
0 | 458 |
} |
459 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
460 |
static Slope GetSlopeTileh_Water(TileIndex tile, Slope tileh) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
461 |
{ |
3418
ec9003ebf933
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3402
diff
changeset
|
462 |
return tileh; |
39 | 463 |
} |
464 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
465 |
static void GetAcceptedCargo_Water(TileIndex tile, AcceptedCargo ac) |
0 | 466 |
{ |
467 |
/* not used */ |
|
468 |
} |
|
469 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
470 |
static void GetTileDesc_Water(TileIndex tile, TileDesc *td) |
0 | 471 |
{ |
3402
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
472 |
switch (GetWaterTileType(tile)) { |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
473 |
case WATER_CLEAR: |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
474 |
if (TilePixelHeight(tile) == 0) { |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
475 |
td->str = STR_3804_WATER; |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
476 |
} else { |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
477 |
td->str = STR_LANDINFO_CANAL; |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
478 |
} |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
479 |
break; |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
480 |
case WATER_COAST: td->str = STR_3805_COAST_OR_RIVERBANK; break; |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
481 |
case WATER_LOCK : td->str = STR_LANDINFO_LOCK; break; |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
482 |
case WATER_DEPOT: td->str = STR_3806_SHIP_DEPOT; break; |
812f9dc4baff
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents:
3373
diff
changeset
|
483 |
default: assert(0); break; |
2951 | 484 |
} |
0 | 485 |
|
1901
03bf9bf99319
(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
|
486 |
td->owner = GetTileOwner(tile); |
0 | 487 |
} |
488 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
489 |
static void AnimateTile_Water(TileIndex tile) |
0 | 490 |
{ |
491 |
/* not used */ |
|
492 |
} |
|
493 |
||
1075 | 494 |
static void TileLoopWaterHelper(TileIndex tile, const TileIndexDiffC *offs) |
0 | 495 |
{ |
1075 | 496 |
TileIndex target = TILE_ADD(tile, ToTileIndexDiff(offs[0])); |
0 | 497 |
|
498 |
// type of this tile mustn't be water already. |
|
2639 | 499 |
if (IsTileType(target, MP_WATER)) return; |
0 | 500 |
|
1075 | 501 |
if (TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[1]))) != 0 || |
2639 | 502 |
TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[2]))) != 0) { |
1075 | 503 |
return; |
2639 | 504 |
} |
1075 | 505 |
|
506 |
if (TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[3]))) != 0 || |
|
507 |
TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[4]))) != 0) { |
|
0 | 508 |
// make coast.. |
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
509 |
switch (GetTileType(target)) { |
1076
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
510 |
case MP_RAILWAY: { |
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3234
diff
changeset
|
511 |
TrackBits tracks; |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
512 |
Slope slope; |
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3234
diff
changeset
|
513 |
|
3275 | 514 |
if (!IsPlainRailTile(target)) break; |
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3234
diff
changeset
|
515 |
|
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3234
diff
changeset
|
516 |
tracks = GetTrackBits(target); |
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3234
diff
changeset
|
517 |
slope = GetTileSlope(target, NULL); |
1076
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
518 |
if (!( |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
519 |
(slope == SLOPE_W && tracks == TRACK_BIT_RIGHT) || |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
520 |
(slope == SLOPE_S && tracks == TRACK_BIT_UPPER) || |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
521 |
(slope == SLOPE_E && tracks == TRACK_BIT_LEFT) || |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
522 |
(slope == SLOPE_N && tracks == TRACK_BIT_LOWER) |
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3234
diff
changeset
|
523 |
)) { |
1076
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
524 |
break; |
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3234
diff
changeset
|
525 |
} |
1076
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
526 |
} |
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
527 |
/* FALLTHROUGH */ |
03a5f2b0a5c2
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
528 |
|
1075 | 529 |
case MP_CLEAR: |
530 |
case MP_TREES: |
|
531 |
_current_player = OWNER_WATER; |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
532 |
if (!CmdFailed(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) { |
3111
750f37699a13
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
533 |
MakeShore(target); |
750f37699a13
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
534 |
MarkTileDirtyByTile(target); |
1075 | 535 |
} |
536 |
break; |
|
537 |
||
1091
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1076
diff
changeset
|
538 |
case MP_TUNNELBRIDGE: |
3234
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3189
diff
changeset
|
539 |
if (IsBridge(target) && IsBridgeMiddle(target) && IsClearUnderBridge(target)) { |
3189
bf047128dee7
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3183
diff
changeset
|
540 |
SetWaterUnderBridge(target); |
3165
0d54b953fb10
(svn r3792) -Fix: Mark the right tile as dirty. It's just a graphical glitch which happend in r1592
tron
parents:
3157
diff
changeset
|
541 |
MarkTileDirtyByTile(target); |
1091
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1076
diff
changeset
|
542 |
} |
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1076
diff
changeset
|
543 |
break; |
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1076
diff
changeset
|
544 |
|
1075 | 545 |
default: |
546 |
break; |
|
0 | 547 |
} |
548 |
} else { |
|
3234
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3189
diff
changeset
|
549 |
if (IsBridgeTile(target) && IsBridgeMiddle(target)) { |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3189
diff
changeset
|
550 |
if (IsWaterUnderBridge(target) || |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3189
diff
changeset
|
551 |
(IsTransportUnderBridge(target) && GetTransportTypeUnderBridge(target) == TRANSPORT_WATER)) { // XXX does this happen at all? |
0 | 552 |
return; |
553 |
} |
|
3234
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3189
diff
changeset
|
554 |
SetWaterUnderBridge(target); |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3189
diff
changeset
|
555 |
MarkTileDirtyByTile(target); |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3189
diff
changeset
|
556 |
return; |
0 | 557 |
} |
558 |
||
559 |
_current_player = OWNER_WATER; |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
560 |
{ |
1605
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1399
diff
changeset
|
561 |
Vehicle *v = FindVehicleOnTileZ(target, 0); |
1075 | 562 |
if (v != NULL) FloodVehicle(v); |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
563 |
} |
1075 | 564 |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
565 |
if (!CmdFailed(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) { |
3111
750f37699a13
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
566 |
MakeWater(target); |
750f37699a13
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
567 |
MarkTileDirtyByTile(target); |
1075 | 568 |
} |
0 | 569 |
} |
570 |
} |
|
571 |
||
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
572 |
static void FloodVehicle(Vehicle *v) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
573 |
{ |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
574 |
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
|
575 |
uint16 pass = 0; |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
576 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
577 |
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
|
578 |
pass = 1; // driver |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
579 |
if (v->cargo_type == CT_PASSENGERS) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
580 |
pass += v->cargo_count; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
581 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
582 |
v->vehstatus |= VS_CRASHED; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
583 |
v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast |
588 | 584 |
RebuildVehicleLists(); |
2549 | 585 |
} else if (v->type == VEH_Train) { |
586 |
Vehicle* u; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
587 |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
588 |
v = GetFirstVehicleInChain(v); |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
589 |
u = v; |
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2657
diff
changeset
|
590 |
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
|
591 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
592 |
// crash all wagons, and count passangers |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
593 |
BEGIN_ENUM_WAGONS(v) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
594 |
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
|
595 |
v->vehstatus |= VS_CRASHED; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
596 |
END_ENUM_WAGONS(v) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
597 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
598 |
v = u; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
599 |
v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast |
588 | 600 |
RebuildVehicleLists(); |
2549 | 601 |
} else { |
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
602 |
return; |
2549 | 603 |
} |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
604 |
|
755
80091de50044
(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
|
605 |
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
|
606 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
607 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
608 |
SetDParam(0, pass); |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
609 |
AddNewsItem(STR_B006_FLOOD_VEHICLE_DESTROYED, |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
610 |
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
|
611 |
v->index, |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
612 |
0); |
2549 | 613 |
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); |
614 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
|
714
503e96f37d46
(svn r1166) Fix: [ 1040119 ] Flooded wagons in depots don't keep constantly exploding any more
dominik
parents:
679
diff
changeset
|
615 |
} |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
616 |
} |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
617 |
|
0 | 618 |
// called from tunnelbridge_cmd |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
619 |
void TileLoop_Water(TileIndex tile) |
0 | 620 |
{ |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
621 |
static const TileIndexDiffC _tile_loop_offs_array[][5] = { |
0 | 622 |
// tile to mod shore? shore? |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
623 |
{{-1, 0}, {0, 0}, {0, 1}, {-1, 0}, {-1, 1}}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
624 |
{{ 0, 1}, {0, 1}, {1, 1}, { 0, 2}, { 1, 2}}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
625 |
{{ 1, 0}, {1, 0}, {1, 1}, { 2, 0}, { 2, 1}}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
626 |
{{ 0, -1}, {0, 0}, {1, 0}, { 0, -1}, { 1, -1}} |
0 | 627 |
}; |
628 |
||
926
a6d140a6a4de
(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
|
629 |
if (IS_INT_INSIDE(TileX(tile), 1, MapSizeX() - 3 + 1) && |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
630 |
IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) { |
2989 | 631 |
uint i; |
632 |
||
2639 | 633 |
for (i = 0; i != lengthof(_tile_loop_offs_array); i++) { |
0 | 634 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[i]); |
2639 | 635 |
} |
0 | 636 |
} |
314 | 637 |
// _current_player can be changed by TileLoopWaterHelper.. reset it back |
638 |
// here |
|
639 |
_current_player = OWNER_NONE; |
|
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
640 |
|
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
641 |
// edges |
2951 | 642 |
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
|
643 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[2]); |
2951 | 644 |
} |
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
645 |
|
2639 | 646 |
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
|
647 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[0]); |
2639 | 648 |
} |
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
649 |
|
2639 | 650 |
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
|
651 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[1]); |
2639 | 652 |
} |
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
653 |
|
2639 | 654 |
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
|
655 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[3]); |
2639 | 656 |
} |
0 | 657 |
} |
658 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
659 |
static uint32 GetTileTrackStatus_Water(TileIndex tile, TransportType mode) |
0 | 660 |
{ |
3423
dab85d82708b
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
661 |
static const byte coast_tracks[] = {0, 32, 4, 0, 16, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0}; |
dab85d82708b
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
662 |
static const byte water_tracks_by_axis[] = {1, 2}; |
2951 | 663 |
if (mode != TRANSPORT_WATER) return 0; |
0 | 664 |
|
3423
dab85d82708b
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
665 |
switch (GetWaterTileType(tile)) { |
dab85d82708b
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
666 |
case WATER_CLEAR: return 0x3F * 0x101; /* We can go everywhere */ |
dab85d82708b
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
667 |
case WATER_COAST: return coast_tracks[GetTileSlope(tile, NULL) & 0xF] * 0x101; |
dab85d82708b
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
668 |
case WATER_LOCK: return water_tracks_by_axis[DiagDirToAxis(GetLockDirection(tile))] * 0x101; |
dab85d82708b
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
669 |
case WATER_DEPOT: return water_tracks_by_axis[GetShipDepotAxis(tile)] * 0x101; |
dab85d82708b
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
670 |
default: return 0; |
0 | 671 |
} |
672 |
} |
|
673 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
674 |
extern void ShowShipDepotWindow(TileIndex tile); |
0 | 675 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
676 |
static void ClickTile_Water(TileIndex tile) |
0 | 677 |
{ |
3423
dab85d82708b
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
678 |
if (GetWaterTileType(tile) == WATER_DEPOT) { |
dab85d82708b
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
679 |
TileIndex tile2 = GetOtherShipDepotTile(tile); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
680 |
|
3423
dab85d82708b
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
681 |
ShowShipDepotWindow(tile < tile2 ? tile : tile2); |
0 | 682 |
} |
683 |
} |
|
684 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2261
diff
changeset
|
685 |
static void ChangeTileOwner_Water(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 686 |
{ |
1901
03bf9bf99319
(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
|
687 |
if (!IsTileOwner(tile, old_player)) return; |
0 | 688 |
|
2502 | 689 |
if (new_player != OWNER_SPECTATOR) { |
1902 | 690 |
SetTileOwner(tile, new_player); |
0 | 691 |
} else { |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3439
diff
changeset
|
692 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 693 |
} |
694 |
} |
|
695 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
696 |
static uint32 VehicleEnter_Water(Vehicle *v, TileIndex tile, int x, int y) |
0 | 697 |
{ |
698 |
return 0; |
|
699 |
} |
|
700 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1091
diff
changeset
|
701 |
void InitializeDock(void) |
0 | 702 |
{ |
703 |
_last_built_ship_depot_tile = 0; |
|
704 |
} |
|
705 |
||
706 |
const TileTypeProcs _tile_type_water_procs = { |
|
707 |
DrawTile_Water, /* draw_tile_proc */ |
|
708 |
GetSlopeZ_Water, /* get_slope_z_proc */ |
|
709 |
ClearTile_Water, /* clear_tile_proc */ |
|
710 |
GetAcceptedCargo_Water, /* get_accepted_cargo_proc */ |
|
711 |
GetTileDesc_Water, /* get_tile_desc_proc */ |
|
712 |
GetTileTrackStatus_Water, /* get_tile_track_status_proc */ |
|
713 |
ClickTile_Water, /* click_tile_proc */ |
|
714 |
AnimateTile_Water, /* animate_tile_proc */ |
|
715 |
TileLoop_Water, /* tile_loop_clear */ |
|
716 |
ChangeTileOwner_Water, /* change_tile_owner_clear */ |
|
717 |
NULL, /* get_produced_cargo_proc */ |
|
718 |
VehicleEnter_Water, /* vehicle_enter_tile_proc */ |
|
39 | 719 |
GetSlopeTileh_Water, /* get_slope_tileh_proc */ |
0 | 720 |
}; |