author | tron |
Tue, 04 Apr 2006 06:01:45 +0000 | |
changeset 3439 | af9ed14f232c |
parent 3436 | 3bc35b8a545c |
child 3491 | 4c8427796c64 |
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" |
3189
1af302c5abd0
(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
2c60ed0dcce3
(svn r4120) Use the new station functions where appropriate
tron
parents:
3275
diff
changeset
|
6 |
#include "station_map.h" |
1363
01d3de5d8039
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1359
diff
changeset
|
7 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
8 |
#include "table/strings.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
9 |
#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
|
10 |
#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
|
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
66647f97e7c0
(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
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
18 |
#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
|
19 |
#include "vehicle_gui.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2657
diff
changeset
|
20 |
#include "train.h" |
3111
1edf71aa942e
(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
3f78323707bb
(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
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2502
diff
changeset
|
24 |
0, |
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_1, |
b90693227193
(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, |
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_3, |
b90693227193
(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, |
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2502
diff
changeset
|
29 |
0, |
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_6, |
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 |
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
|
33 |
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
|
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, |
b90693227193
(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, |
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2502
diff
changeset
|
37 |
0, |
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2502
diff
changeset
|
38 |
0 |
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2186
diff
changeset
|
39 |
}; |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2186
diff
changeset
|
40 |
|
3f78323707bb
(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
6eb3ab1bc33c
(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. |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1752
diff
changeset
|
45 |
* @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
|
46 |
* @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
|
47 |
* @param p2 unused |
0 | 48 |
*/ |
49 |
int32 CmdBuildShipDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
50 |
{ |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1752
diff
changeset
|
51 |
TileIndex tile, 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
bba6afb8a995
(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
d72100c6a799
(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
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1752
diff
changeset
|
59 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
60 |
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
|
61 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 62 |
|
1981 | 63 |
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
|
64 |
if (!EnsureNoVehicle(tile2)) return CMD_ERROR; |
0 | 65 |
|
66 |
if (!IsClearWaterTile(tile) || !IsClearWaterTile(tile2)) |
|
67 |
return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER); |
|
68 |
||
69 |
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
|
70 |
if (CmdFailed(ret)) return CMD_ERROR; |
0 | 71 |
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
|
72 |
if (CmdFailed(ret)) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
73 |
|
0 | 74 |
// pretend that we're not making land from the water even though we actually are. |
75 |
cost = 0; |
|
76 |
||
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
77 |
depot = AllocateDepot(); |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1752
diff
changeset
|
78 |
if (depot == NULL) return CMD_ERROR; |
0 | 79 |
|
80 |
if (flags & DC_EXEC) { |
|
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
81 |
depot->xy = tile; |
0 | 82 |
_last_built_ship_depot_tile = tile; |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1214
diff
changeset
|
83 |
depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
0 | 84 |
|
3372
e9eaf986b264
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents:
3338
diff
changeset
|
85 |
MakeShipDepot(tile,_current_player, DEPOT_NORTH, p1); |
e9eaf986b264
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents:
3338
diff
changeset
|
86 |
MakeShipDepot(tile2,_current_player, DEPOT_SOUTH, p1); |
e9eaf986b264
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents:
3338
diff
changeset
|
87 |
MarkTileDirtyByTile(tile); |
e9eaf986b264
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents:
3338
diff
changeset
|
88 |
MarkTileDirtyByTile(tile2); |
0 | 89 |
} |
90 |
||
91 |
return cost + _price.build_ship_depot; |
|
92 |
} |
|
93 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
94 |
static int32 RemoveShipDepot(TileIndex tile, uint32 flags) |
0 | 95 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
96 |
TileIndex tile2; |
0 | 97 |
|
3373
f95cf3549591
(svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents:
3372
diff
changeset
|
98 |
if (!IsShipDepot(tile)) return CMD_ERROR; |
2951 | 99 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
100 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
|
0 | 101 |
|
3373
f95cf3549591
(svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents:
3372
diff
changeset
|
102 |
tile2 = GetOtherShipDepotTile(tile); |
0 | 103 |
|
2951 | 104 |
if (!EnsureNoVehicle(tile2)) return CMD_ERROR; |
0 | 105 |
|
106 |
if (flags & DC_EXEC) { |
|
3373
f95cf3549591
(svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents:
3372
diff
changeset
|
107 |
/* Kill the depot, which is registered at the northernmost tile. Use that one */ |
f95cf3549591
(svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents:
3372
diff
changeset
|
108 |
DoDeleteDepot(tile2 < tile ? tile2 : tile); |
0 | 109 |
|
3111
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
110 |
MakeWater(tile); |
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
111 |
MakeWater(tile2); |
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
112 |
MarkTileDirtyByTile(tile); |
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
113 |
MarkTileDirtyByTile(tile2); |
0 | 114 |
} |
115 |
||
116 |
return _price.remove_ship_depot; |
|
117 |
} |
|
118 |
||
119 |
// build a shiplift |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3111
diff
changeset
|
120 |
static int32 DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags) |
0 | 121 |
{ |
122 |
int32 ret; |
|
123 |
int delta; |
|
124 |
||
125 |
// middle tile |
|
126 |
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
|
127 |
if (CmdFailed(ret)) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
128 |
|
900 | 129 |
delta = TileOffsByDir(dir); |
0 | 130 |
// lower tile |
131 |
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
|
132 |
if (CmdFailed(ret)) return CMD_ERROR; |
0 | 133 |
if (GetTileSlope(tile - delta, NULL)) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
134 |
||
135 |
// upper tile |
|
136 |
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
|
137 |
if (CmdFailed(ret)) return CMD_ERROR; |
0 | 138 |
if (GetTileSlope(tile + delta, NULL)) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
139 |
||
140 |
if (flags & DC_EXEC) { |
|
3372
e9eaf986b264
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents:
3338
diff
changeset
|
141 |
MakeLock(tile, dir); |
e9eaf986b264
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents:
3338
diff
changeset
|
142 |
MarkTileDirtyByTile(tile); |
e9eaf986b264
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents:
3338
diff
changeset
|
143 |
MarkTileDirtyByTile(tile - delta); |
e9eaf986b264
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents:
3338
diff
changeset
|
144 |
MarkTileDirtyByTile(tile + delta); |
0 | 145 |
} |
146 |
||
147 |
return _price.clear_water * 22 >> 3; |
|
148 |
} |
|
149 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
150 |
static int32 RemoveShiplift(TileIndex tile, uint32 flags) |
0 | 151 |
{ |
3373
f95cf3549591
(svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents:
3372
diff
changeset
|
152 |
TileIndexDiff delta = TileOffsByDir(GetLockDirection(tile)); |
0 | 153 |
|
154 |
// make sure no vehicle is on the tile. |
|
155 |
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(tile + delta) || !EnsureNoVehicle(tile - delta)) |
|
156 |
return CMD_ERROR; |
|
157 |
||
158 |
if (flags & DC_EXEC) { |
|
159 |
DoClearSquare(tile); |
|
160 |
DoClearSquare(tile + delta); |
|
161 |
DoClearSquare(tile - delta); |
|
162 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
163 |
|
0 | 164 |
return _price.clear_water * 2; |
165 |
} |
|
166 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
167 |
static void MarkTilesAroundDirty(TileIndex tile) |
0 | 168 |
{ |
169 |
MarkTileDirtyByTile(TILE_ADDXY(tile, 0, 1)); |
|
170 |
MarkTileDirtyByTile(TILE_ADDXY(tile, 0, -1)); |
|
171 |
MarkTileDirtyByTile(TILE_ADDXY(tile, 1, 0)); |
|
172 |
MarkTileDirtyByTile(TILE_ADDXY(tile, -1, 0)); |
|
173 |
} |
|
174 |
||
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1784
diff
changeset
|
175 |
/** 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
|
176 |
* @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
|
177 |
* @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
|
178 |
* @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
|
179 |
*/ |
0 | 180 |
int32 CmdBuildLock(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
181 |
{ |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
182 |
TileIndex tile = TileVirtXY(x, y); |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3111
diff
changeset
|
183 |
DiagDirection dir; |
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
|
184 |
|
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
|
185 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
0 | 186 |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3111
diff
changeset
|
187 |
switch (GetTileSlope(tile, NULL)) { |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3111
diff
changeset
|
188 |
case 3: dir = DIAGDIR_SW; break; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3111
diff
changeset
|
189 |
case 6: dir = DIAGDIR_SE; break; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3111
diff
changeset
|
190 |
case 9: dir = DIAGDIR_NW; break; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3111
diff
changeset
|
191 |
case 12: dir = DIAGDIR_NE; break; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3111
diff
changeset
|
192 |
default: return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1784
diff
changeset
|
193 |
} |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3111
diff
changeset
|
194 |
return DoBuildShiplift(tile, dir, flags); |
0 | 195 |
} |
196 |
||
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 |
/** 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
|
198 |
* @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
|
199 |
* @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
|
200 |
* @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
|
201 |
*/ |
0 | 202 |
int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
203 |
{ |
|
3177 | 204 |
int32 cost; |
1632
c4ae19bfebf7
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
Darkvater
parents:
1605
diff
changeset
|
205 |
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
|
206 |
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
|
207 |
|
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
|
208 |
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
|
209 |
|
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 |
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
|
211 |
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
|
212 |
/* 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
|
213 |
* 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
|
214 |
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
|
215 |
|
0 | 216 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
217 |
||
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
|
218 |
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
|
219 |
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
|
220 |
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
|
221 |
size_y = (y - sy) + 1; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
222 |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1784
diff
changeset
|
223 |
/* 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
|
224 |
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
|
225 |
|
0 | 226 |
cost = 0; |
1981 | 227 |
BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) { |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1784
diff
changeset
|
228 |
if (GetTileSlope(tile, NULL) != 0) return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
0 | 229 |
|
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
230 |
// can't make water of water! |
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
231 |
if (IsTileType(tile, MP_WATER)) continue; |
1632
c4ae19bfebf7
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
Darkvater
parents:
1605
diff
changeset
|
232 |
|
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
233 |
/* is middle piece of a bridge? */ |
3234
986c30171e92
(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
|
234 |
if (IsBridgeTile(tile) && IsBridgeMiddle(tile)) { |
986c30171e92
(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
|
235 |
if (IsTransportUnderBridge(tile)) { |
3183
cf71bd234ebd
(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 |
return_cmd_error(STR_5800_OBJECT_IN_THE_WAY); |
3234
986c30171e92
(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
|
237 |
} |
3177 | 238 |
|
3234
986c30171e92
(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 (IsWaterUnderBridge(tile)) return_cmd_error(STR_1007_ALREADY_BUILT); |
3177 | 240 |
|
3189
1af302c5abd0
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3183
diff
changeset
|
241 |
if (flags & DC_EXEC) SetWaterUnderBridge(tile); |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
242 |
} else { |
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
243 |
/* no bridge, try to clear it. */ |
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
244 |
int32 ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
0 | 245 |
|
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
246 |
if (CmdFailed(ret)) return ret; |
cf71bd234ebd
(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 |
cost += ret; |
3177 | 248 |
|
3189
1af302c5abd0
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3183
diff
changeset
|
249 |
if (flags & DC_EXEC) MakeWater(tile); |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
250 |
} |
cf71bd234ebd
(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 |
|
3189
1af302c5abd0
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3183
diff
changeset
|
252 |
if (flags & DC_EXEC) { |
1af302c5abd0
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3183
diff
changeset
|
253 |
MarkTileDirtyByTile(tile); |
1af302c5abd0
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3183
diff
changeset
|
254 |
MarkTilesAroundDirty(tile); |
1af302c5abd0
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3183
diff
changeset
|
255 |
} |
3183
cf71bd234ebd
(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 |
|
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
257 |
cost += _price.clear_water; |
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
|
258 |
} END_TILE_LOOP(tile, size_x, size_y, 0); |
0 | 259 |
|
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
260 |
if (cost == 0) { |
cf71bd234ebd
(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 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
cf71bd234ebd
(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 |
} else { |
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
263 |
return cost; |
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3177
diff
changeset
|
264 |
} |
0 | 265 |
} |
266 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
267 |
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
|
268 |
{ |
3425
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
269 |
switch (GetWaterTileType(tile)) { |
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
270 |
case WATER_CLEAR: |
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
271 |
if (flags & DC_NO_WATER) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
0 | 272 |
|
3425
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
273 |
// Make sure no vehicle is on the tile |
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
274 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 275 |
|
3425
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
276 |
// Make sure it's not an edge tile. |
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
277 |
if (!IS_INT_INSIDE(TileX(tile), 1, MapMaxX() - 1) || |
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
278 |
!IS_INT_INSIDE(TileY(tile), 1, MapMaxY() - 1)) { |
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
279 |
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP); |
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
280 |
} |
3017
915fae59d5e0
(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
|
281 |
|
915fae59d5e0
(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
|
282 |
if (flags & DC_EXEC) DoClearSquare(tile); |
3425
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
283 |
return _price.clear_water; |
0 | 284 |
|
3439 | 285 |
case WATER_COAST: { |
286 |
uint slope = GetTileSlope(tile, NULL); |
|
287 |
||
288 |
// Make sure no vehicle is on the tile |
|
289 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
|
290 |
||
291 |
// Make sure it's not an edge tile. |
|
292 |
if (!IS_INT_INSIDE(TileX(tile), 1, MapMaxX() - 1) || |
|
293 |
!IS_INT_INSIDE(TileY(tile), 1, MapMaxY() - 1)) { |
|
294 |
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP); |
|
3425
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
295 |
} |
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
296 |
|
3439 | 297 |
if (flags & DC_EXEC) DoClearSquare(tile); |
298 |
if (slope == 8 || slope == 4 || slope == 2 || slope == 1) { |
|
299 |
return _price.clear_water; |
|
300 |
} else { |
|
301 |
return _price.purchase_land; |
|
3425
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
302 |
} |
3439 | 303 |
} |
304 |
||
305 |
case WATER_LOCK: { |
|
306 |
static const TileIndexDiffC _shiplift_tomiddle_offs[] = { |
|
307 |
{ 0, 0}, {0, 0}, { 0, 0}, {0, 0}, // middle |
|
308 |
{-1, 0}, {0, 1}, { 1, 0}, {0, -1}, // lower |
|
309 |
{ 1, 0}, {0, -1}, {-1, 0}, {0, 1}, // upper |
|
310 |
}; |
|
311 |
||
312 |
if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
313 |
if (_current_player == OWNER_WATER) return CMD_ERROR; |
|
314 |
// move to the middle tile.. |
|
315 |
return RemoveShiplift(tile + ToTileIndexDiff(_shiplift_tomiddle_offs[GetSection(tile)]), flags); |
|
316 |
} |
|
317 |
||
3425
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
318 |
case WATER_DEPOT: |
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
319 |
if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
320 |
|
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
321 |
return RemoveShipDepot(tile, flags); |
3439 | 322 |
|
323 |
default: |
|
324 |
NOT_REACHED(); |
|
325 |
return 0; |
|
0 | 326 |
} |
327 |
} |
|
328 |
||
329 |
// return true if a tile is a water tile. |
|
1048 | 330 |
static bool IsWateredTile(TileIndex tile) |
0 | 331 |
{ |
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
332 |
switch (GetTileType(tile)) { |
1048 | 333 |
case MP_WATER: |
3423
03e0e97abf41
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
334 |
return !IsCoast(tile); |
1048 | 335 |
|
336 |
case MP_STATION: |
|
3338
2c60ed0dcce3
(svn r4120) Use the new station functions where appropriate
tron
parents:
3275
diff
changeset
|
337 |
return IsOilRig(tile) || IsDock(tile) || IsBuoy_(tile); |
1048 | 338 |
|
339 |
case MP_TUNNELBRIDGE: |
|
3234
986c30171e92
(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
|
340 |
return IsBridge(tile) && IsBridgeMiddle(tile) && IsWaterUnderBridge(tile); |
1048 | 341 |
|
342 |
default: |
|
343 |
return false; |
|
344 |
} |
|
0 | 345 |
} |
346 |
||
347 |
// 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
|
348 |
void DrawCanalWater(TileIndex tile) |
0 | 349 |
{ |
350 |
uint wa; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
351 |
|
0 | 352 |
// determine the edges around with water. |
353 |
wa = IsWateredTile(TILE_ADDXY(tile, -1, 0)) << 0; |
|
354 |
wa += IsWateredTile(TILE_ADDXY(tile, 0, 1)) << 1; |
|
355 |
wa += IsWateredTile(TILE_ADDXY(tile, 1, 0)) << 2; |
|
356 |
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
|
357 |
|
0 | 358 |
if (!(wa & 1)) DrawGroundSprite(SPR_CANALS_BASE + 57); |
359 |
if (!(wa & 2)) DrawGroundSprite(SPR_CANALS_BASE + 58); |
|
360 |
if (!(wa & 4)) DrawGroundSprite(SPR_CANALS_BASE + 59); |
|
361 |
if (!(wa & 8)) DrawGroundSprite(SPR_CANALS_BASE + 60); |
|
362 |
||
363 |
// right corner |
|
2989 | 364 |
switch (wa & 0x03) { |
365 |
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 4); break; |
|
366 |
case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 8); break; |
|
367 |
} |
|
0 | 368 |
|
369 |
// bottom corner |
|
2989 | 370 |
switch (wa & 0x06) { |
371 |
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 5); break; |
|
372 |
case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 9); break; |
|
373 |
} |
|
0 | 374 |
|
375 |
// left corner |
|
2989 | 376 |
switch (wa & 0x0C) { |
377 |
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 6); break; |
|
378 |
case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 10); break; |
|
379 |
} |
|
0 | 380 |
|
381 |
// upper corner |
|
2989 | 382 |
switch (wa & 0x09) { |
383 |
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 7); break; |
|
384 |
case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 11); break; |
|
385 |
} |
|
0 | 386 |
} |
387 |
||
388 |
typedef struct LocksDrawTileStruct { |
|
389 |
int8 delta_x, delta_y, delta_z; |
|
390 |
byte width, height, depth; |
|
391 |
SpriteID image; |
|
392 |
} LocksDrawTileStruct; |
|
393 |
||
394 |
#include "table/water_land.h" |
|
395 |
||
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
|
396 |
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
|
397 |
uint32 palette, uint base |
4503bd2bfb82
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
398 |
) |
0 | 399 |
{ |
1399
4503bd2bfb82
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
400 |
DrawGroundSprite(wdts++->image); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
401 |
|
1399
4503bd2bfb82
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
402 |
for (; wdts->delta_x != 0x80; wdts++) { |
2989 | 403 |
uint32 image = wdts->image + base; |
0 | 404 |
if (_display_opt & DO_TRANS_BUILDINGS) { |
2148
47ba4a1b1c3b
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2049
diff
changeset
|
405 |
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
|
406 |
} else { |
0 | 407 |
image |= palette; |
408 |
} |
|
409 |
AddSortableSpriteToDraw(image, ti->x + wdts->delta_x, ti->y + wdts->delta_y, wdts->width, wdts->height, wdts->unk, ti->z + wdts->delta_z); |
|
410 |
} |
|
411 |
} |
|
412 |
||
413 |
static void DrawTile_Water(TileInfo *ti) |
|
414 |
{ |
|
3402
0b72e324d300
(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
|
415 |
switch (GetWaterTileType(ti->tile)) { |
0b72e324d300
(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
|
416 |
case WATER_CLEAR: |
0b72e324d300
(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
|
417 |
DrawGroundSprite(SPR_FLAT_WATER_TILE); |
0b72e324d300
(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
|
418 |
if (ti->z != 0) DrawCanalWater(ti->tile); |
0b72e324d300
(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
|
419 |
break; |
0 | 420 |
|
3402
0b72e324d300
(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_COAST: |
3422
12cdb13ddb56
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3418
diff
changeset
|
422 |
assert(!IsSteepTileh(ti->tileh)); |
3402
0b72e324d300
(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 |
DrawGroundSprite(_water_shore_sprites[ti->tileh]); |
0b72e324d300
(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
0b72e324d300
(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_LOCK: { |
3425
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
427 |
const WaterDrawTileStruct *t = _shiplift_display_seq[GetSection(ti->tile)]; |
3402
0b72e324d300
(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 |
DrawWaterStuff(ti, t, 0, ti->z > t[3].delta_y ? 24 : 0); |
0b72e324d300
(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; |
0b72e324d300
(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
|
430 |
|
0b72e324d300
(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_DEPOT: |
3425
b972214fde4f
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents:
3423
diff
changeset
|
432 |
DrawWaterStuff(ti, _shipdepot_display_seq[GetSection(ti->tile)], PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), 0); |
3402
0b72e324d300
(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 |
break; |
0 | 434 |
} |
435 |
} |
|
436 |
||
437 |
void DrawShipDepotSprite(int x, int y, int image) |
|
438 |
{ |
|
1399
4503bd2bfb82
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
439 |
const WaterDrawTileStruct *wdts = _shipdepot_display_seq[image]; |
0 | 440 |
|
1399
4503bd2bfb82
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
441 |
DrawSprite(wdts++->image, x, y); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
442 |
|
1399
4503bd2bfb82
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
443 |
for (; wdts->delta_x != 0x80; wdts++) { |
0 | 444 |
Point pt = RemapCoords(wdts->delta_x, wdts->delta_y, wdts->delta_z); |
445 |
DrawSprite(wdts->image + PLAYER_SPRITE_COLOR(_local_player), x + pt.x, y + pt.y); |
|
446 |
} |
|
447 |
} |
|
448 |
||
449 |
||
2537 | 450 |
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
|
451 |
{ |
2537 | 452 |
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z; |
0 | 453 |
} |
454 |
||
3418
a592d40a4d04
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3402
diff
changeset
|
455 |
static uint GetSlopeTileh_Water(TileIndex tile, uint tileh) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
456 |
{ |
3418
a592d40a4d04
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3402
diff
changeset
|
457 |
return tileh; |
39 | 458 |
} |
459 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
460 |
static void GetAcceptedCargo_Water(TileIndex tile, AcceptedCargo ac) |
0 | 461 |
{ |
462 |
/* not used */ |
|
463 |
} |
|
464 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
465 |
static void GetTileDesc_Water(TileIndex tile, TileDesc *td) |
0 | 466 |
{ |
3402
0b72e324d300
(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
|
467 |
switch (GetWaterTileType(tile)) { |
0b72e324d300
(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
|
468 |
case WATER_CLEAR: |
0b72e324d300
(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
|
469 |
if (TilePixelHeight(tile) == 0) { |
0b72e324d300
(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
|
470 |
td->str = STR_3804_WATER; |
0b72e324d300
(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
|
471 |
} else { |
0b72e324d300
(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 |
td->str = STR_LANDINFO_CANAL; |
0b72e324d300
(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 |
} |
0b72e324d300
(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 |
break; |
0b72e324d300
(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 |
case WATER_COAST: td->str = STR_3805_COAST_OR_RIVERBANK; break; |
0b72e324d300
(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 |
case WATER_LOCK : td->str = STR_LANDINFO_LOCK; break; |
0b72e324d300
(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 |
case WATER_DEPOT: td->str = STR_3806_SHIP_DEPOT; break; |
0b72e324d300
(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 |
default: assert(0); break; |
2951 | 479 |
} |
0 | 480 |
|
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
|
481 |
td->owner = GetTileOwner(tile); |
0 | 482 |
} |
483 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
484 |
static void AnimateTile_Water(TileIndex tile) |
0 | 485 |
{ |
486 |
/* not used */ |
|
487 |
} |
|
488 |
||
1075 | 489 |
static void TileLoopWaterHelper(TileIndex tile, const TileIndexDiffC *offs) |
0 | 490 |
{ |
1075 | 491 |
TileIndex target = TILE_ADD(tile, ToTileIndexDiff(offs[0])); |
0 | 492 |
|
493 |
// type of this tile mustn't be water already. |
|
2639 | 494 |
if (IsTileType(target, MP_WATER)) return; |
0 | 495 |
|
1075 | 496 |
if (TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[1]))) != 0 || |
2639 | 497 |
TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[2]))) != 0) { |
1075 | 498 |
return; |
2639 | 499 |
} |
1075 | 500 |
|
501 |
if (TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[3]))) != 0 || |
|
502 |
TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[4]))) != 0) { |
|
0 | 503 |
// 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
|
504 |
switch (GetTileType(target)) { |
1076
ee035f4a90e9
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
505 |
case MP_RAILWAY: { |
3267
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3234
diff
changeset
|
506 |
TrackBits tracks; |
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3234
diff
changeset
|
507 |
uint slope; |
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3234
diff
changeset
|
508 |
|
3275 | 509 |
if (!IsPlainRailTile(target)) break; |
3267
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3234
diff
changeset
|
510 |
|
591027d10884
(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 |
tracks = GetTrackBits(target); |
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3234
diff
changeset
|
512 |
slope = GetTileSlope(target, NULL); |
1076
ee035f4a90e9
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
513 |
if (!( |
3268
0ee220b09578
(svn r3980) Fix glitch in r3979 spotted by Rubidium. Maybe I'm getting too old for this...
tron
parents:
3267
diff
changeset
|
514 |
(slope == 1 && tracks == TRACK_BIT_RIGHT) || |
0ee220b09578
(svn r3980) Fix glitch in r3979 spotted by Rubidium. Maybe I'm getting too old for this...
tron
parents:
3267
diff
changeset
|
515 |
(slope == 2 && tracks == TRACK_BIT_UPPER) || |
0ee220b09578
(svn r3980) Fix glitch in r3979 spotted by Rubidium. Maybe I'm getting too old for this...
tron
parents:
3267
diff
changeset
|
516 |
(slope == 4 && tracks == TRACK_BIT_LEFT) || |
3267
591027d10884
(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 == 8 && tracks == TRACK_BIT_LOWER) |
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3234
diff
changeset
|
518 |
)) { |
1076
ee035f4a90e9
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
519 |
break; |
3267
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3234
diff
changeset
|
520 |
} |
1076
ee035f4a90e9
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
521 |
} |
ee035f4a90e9
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
522 |
/* FALLTHROUGH */ |
ee035f4a90e9
(svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents:
1075
diff
changeset
|
523 |
|
1075 | 524 |
case MP_CLEAR: |
525 |
case MP_TREES: |
|
526 |
_current_player = OWNER_WATER; |
|
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2676
diff
changeset
|
527 |
if (!CmdFailed(DoCommandByTile(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) { |
3111
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
528 |
MakeShore(target); |
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
529 |
MarkTileDirtyByTile(target); |
1075 | 530 |
} |
531 |
break; |
|
532 |
||
1091
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1076
diff
changeset
|
533 |
case MP_TUNNELBRIDGE: |
3234
986c30171e92
(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
|
534 |
if (IsBridge(target) && IsBridgeMiddle(target) && IsClearUnderBridge(target)) { |
3189
1af302c5abd0
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3183
diff
changeset
|
535 |
SetWaterUnderBridge(target); |
3165
e719907e8016
(svn r3792) -Fix: Mark the right tile as dirty. It's just a graphical glitch which happend in r1592
tron
parents:
3157
diff
changeset
|
536 |
MarkTileDirtyByTile(target); |
1091
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1076
diff
changeset
|
537 |
} |
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1076
diff
changeset
|
538 |
break; |
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1076
diff
changeset
|
539 |
|
1075 | 540 |
default: |
541 |
break; |
|
0 | 542 |
} |
543 |
} else { |
|
3234
986c30171e92
(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
|
544 |
if (IsBridgeTile(target) && IsBridgeMiddle(target)) { |
986c30171e92
(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
|
545 |
if (IsWaterUnderBridge(target) || |
986c30171e92
(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
|
546 |
(IsTransportUnderBridge(target) && GetTransportTypeUnderBridge(target) == TRANSPORT_WATER)) { // XXX does this happen at all? |
0 | 547 |
return; |
548 |
} |
|
3234
986c30171e92
(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 |
SetWaterUnderBridge(target); |
986c30171e92
(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 |
MarkTileDirtyByTile(target); |
986c30171e92
(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 |
return; |
0 | 552 |
} |
553 |
||
554 |
_current_player = OWNER_WATER; |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
555 |
{ |
1605
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1399
diff
changeset
|
556 |
Vehicle *v = FindVehicleOnTileZ(target, 0); |
1075 | 557 |
if (v != NULL) FloodVehicle(v); |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
558 |
} |
1075 | 559 |
|
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2676
diff
changeset
|
560 |
if (!CmdFailed(DoCommandByTile(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) { |
3111
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
561 |
MakeWater(target); |
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3017
diff
changeset
|
562 |
MarkTileDirtyByTile(target); |
1075 | 563 |
} |
0 | 564 |
} |
565 |
} |
|
566 |
||
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
567 |
static void FloodVehicle(Vehicle *v) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
568 |
{ |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
569 |
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
|
570 |
uint16 pass = 0; |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
571 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
572 |
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
|
573 |
pass = 1; // driver |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
574 |
if (v->cargo_type == CT_PASSENGERS) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
575 |
pass += v->cargo_count; |
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 |
v->vehstatus |= VS_CRASHED; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
578 |
v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast |
588 | 579 |
RebuildVehicleLists(); |
2549 | 580 |
} else if (v->type == VEH_Train) { |
581 |
Vehicle* u; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
582 |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
583 |
v = GetFirstVehicleInChain(v); |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
584 |
u = v; |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2657
diff
changeset
|
585 |
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
|
586 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
587 |
// crash all wagons, and count passangers |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
588 |
BEGIN_ENUM_WAGONS(v) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
589 |
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
|
590 |
v->vehstatus |= VS_CRASHED; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
591 |
END_ENUM_WAGONS(v) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
592 |
|
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
593 |
v = u; |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
594 |
v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast |
588 | 595 |
RebuildVehicleLists(); |
2549 | 596 |
} else { |
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
597 |
return; |
2549 | 598 |
} |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
599 |
|
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
|
600 |
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
|
601 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
602 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
603 |
SetDParam(0, pass); |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
604 |
AddNewsItem(STR_B006_FLOOD_VEHICLE_DESTROYED, |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
605 |
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
|
606 |
v->index, |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
607 |
0); |
2549 | 608 |
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); |
609 |
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
|
610 |
} |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
611 |
} |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
43
diff
changeset
|
612 |
|
0 | 613 |
// called from tunnelbridge_cmd |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
614 |
void TileLoop_Water(TileIndex tile) |
0 | 615 |
{ |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
616 |
static const TileIndexDiffC _tile_loop_offs_array[][5] = { |
0 | 617 |
// tile to mod shore? shore? |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
618 |
{{-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
|
619 |
{{ 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
|
620 |
{{ 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
|
621 |
{{ 0, -1}, {0, 0}, {1, 0}, { 0, -1}, { 1, -1}} |
0 | 622 |
}; |
623 |
||
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
|
624 |
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
|
625 |
IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) { |
2989 | 626 |
uint i; |
627 |
||
2639 | 628 |
for (i = 0; i != lengthof(_tile_loop_offs_array); i++) { |
0 | 629 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[i]); |
2639 | 630 |
} |
0 | 631 |
} |
314 | 632 |
// _current_player can be changed by TileLoopWaterHelper.. reset it back |
633 |
// here |
|
634 |
_current_player = OWNER_NONE; |
|
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
635 |
|
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
636 |
// edges |
2951 | 637 |
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
|
638 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[2]); |
2951 | 639 |
} |
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
640 |
|
2639 | 641 |
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
|
642 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[0]); |
2639 | 643 |
} |
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
644 |
|
2639 | 645 |
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
|
646 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[1]); |
2639 | 647 |
} |
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
648 |
|
2639 | 649 |
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
|
650 |
TileLoopWaterHelper(tile, _tile_loop_offs_array[3]); |
2639 | 651 |
} |
0 | 652 |
} |
653 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
654 |
static uint32 GetTileTrackStatus_Water(TileIndex tile, TransportType mode) |
0 | 655 |
{ |
3423
03e0e97abf41
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
656 |
static const byte coast_tracks[] = {0, 32, 4, 0, 16, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0}; |
03e0e97abf41
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
657 |
static const byte water_tracks_by_axis[] = {1, 2}; |
2951 | 658 |
if (mode != TRANSPORT_WATER) return 0; |
0 | 659 |
|
3423
03e0e97abf41
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
660 |
switch (GetWaterTileType(tile)) { |
03e0e97abf41
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
661 |
case WATER_CLEAR: return 0x3F * 0x101; /* We can go everywhere */ |
03e0e97abf41
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
662 |
case WATER_COAST: return coast_tracks[GetTileSlope(tile, NULL) & 0xF] * 0x101; |
03e0e97abf41
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
663 |
case WATER_LOCK: return water_tracks_by_axis[DiagDirToAxis(GetLockDirection(tile))] * 0x101; |
03e0e97abf41
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
664 |
case WATER_DEPOT: return water_tracks_by_axis[GetShipDepotAxis(tile)] * 0x101; |
03e0e97abf41
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
665 |
default: return 0; |
0 | 666 |
} |
667 |
} |
|
668 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
669 |
extern void ShowShipDepotWindow(TileIndex tile); |
0 | 670 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
671 |
static void ClickTile_Water(TileIndex tile) |
0 | 672 |
{ |
3423
03e0e97abf41
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
673 |
if (GetWaterTileType(tile) == WATER_DEPOT) { |
03e0e97abf41
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
674 |
TileIndex tile2 = GetOtherShipDepotTile(tile); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
168
diff
changeset
|
675 |
|
3423
03e0e97abf41
(svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents:
3422
diff
changeset
|
676 |
ShowShipDepotWindow(tile < tile2 ? tile : tile2); |
0 | 677 |
} |
678 |
} |
|
679 |
||
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
|
680 |
static void ChangeTileOwner_Water(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 681 |
{ |
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
|
682 |
if (!IsTileOwner(tile, old_player)) return; |
0 | 683 |
|
2502 | 684 |
if (new_player != OWNER_SPECTATOR) { |
1902 | 685 |
SetTileOwner(tile, new_player); |
0 | 686 |
} else { |
687 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
688 |
} |
|
689 |
} |
|
690 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
691 |
static uint32 VehicleEnter_Water(Vehicle *v, TileIndex tile, int x, int y) |
0 | 692 |
{ |
693 |
return 0; |
|
694 |
} |
|
695 |
||
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
|
696 |
void InitializeDock(void) |
0 | 697 |
{ |
698 |
_last_built_ship_depot_tile = 0; |
|
699 |
} |
|
700 |
||
701 |
const TileTypeProcs _tile_type_water_procs = { |
|
702 |
DrawTile_Water, /* draw_tile_proc */ |
|
703 |
GetSlopeZ_Water, /* get_slope_z_proc */ |
|
704 |
ClearTile_Water, /* clear_tile_proc */ |
|
705 |
GetAcceptedCargo_Water, /* get_accepted_cargo_proc */ |
|
706 |
GetTileDesc_Water, /* get_tile_desc_proc */ |
|
707 |
GetTileTrackStatus_Water, /* get_tile_track_status_proc */ |
|
708 |
ClickTile_Water, /* click_tile_proc */ |
|
709 |
AnimateTile_Water, /* animate_tile_proc */ |
|
710 |
TileLoop_Water, /* tile_loop_clear */ |
|
711 |
ChangeTileOwner_Water, /* change_tile_owner_clear */ |
|
712 |
NULL, /* get_produced_cargo_proc */ |
|
713 |
VehicleEnter_Water, /* vehicle_enter_tile_proc */ |
|
714 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 715 |
GetSlopeTileh_Water, /* get_slope_tileh_proc */ |
0 | 716 |
}; |