water_cmd.c
author celestar
Fri, 29 Dec 2006 10:13:35 +0000
branchcustombridgeheads
changeset 5592 fd60d4ecc921
parent 5590 dc34c43fc3eb
permissions -rw-r--r--
(svn r7608) [cbh] - Merge with trunk r7593:7607 because I need 7607 here
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    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"
5210
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 4848
diff changeset
    22
#include "newgrf.h"
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
    23
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
    24
static const SpriteID _water_shore_sprites[] = {
2517
b90693227193 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2502
diff changeset
    25
	0,
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_1,
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_2,
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_3,
b90693227193 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2502
diff changeset
    29
	SPR_SHORE_TILEH_4,
b90693227193 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2502
diff changeset
    30
	0,
b90693227193 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2502
diff changeset
    31
	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
    32
	0,
b90693227193 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2502
diff changeset
    33
	SPR_SHORE_TILEH_8,
b90693227193 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2502
diff changeset
    34
	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
    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
	0,
b90693227193 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2502
diff changeset
    37
	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
    38
	0,
b90693227193 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2502
diff changeset
    39
	0
2261
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
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2186
diff changeset
    42
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
    43
static void FloodVehicle(Vehicle *v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1752
diff changeset
    45
/** Build a ship depot.
3491
4c8427796c64 (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
    46
 * @param tile tile 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
    47
 * @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
    48
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
 */
3491
4c8427796c64 (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
    50
int32 CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
{
3491
4c8427796c64 (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
    52
	TileIndex tile2;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
    53
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
	int32 cost, ret;
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1214
diff changeset
    55
	Depot *depot;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
2657
d72100c6a799 (svn r3199) -Fix: There are only 2 possible directions for ship depots, not 4
tron
parents: 2652
diff changeset
    59
	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
    60
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
    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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
	if (!IsClearWaterTile(tile) || !IsClearWaterTile(tile2))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
		return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
    69
	if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
    70
3491
4c8427796c64 (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
    71
	ret = DoCommand(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
    72
	if (CmdFailed(ret)) return CMD_ERROR;
3491
4c8427796c64 (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
    73
	ret = DoCommand(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
    74
	if (CmdFailed(ret)) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
    75
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
	// pretend that we're not making land from the water even though we actually are.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
	cost = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1214
diff changeset
    79
	depot = AllocateDepot();
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1752
diff changeset
    80
	if (depot == NULL) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
	if (flags & DC_EXEC) {
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1214
diff changeset
    83
		depot->xy = tile;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1214
diff changeset
    84
		depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
3372
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(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
    87
		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
    88
		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
    89
		MarkTileDirtyByTile(tile2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
	return cost + _price.build_ship_depot;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
    95
static int32 RemoveShipDepot(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
{
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
    97
	TileIndex tile2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
3373
f95cf3549591 (svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents: 3372
diff changeset
    99
	if (!IsShipDepot(tile)) return CMD_ERROR;
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   100
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   101
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
3373
f95cf3549591 (svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents: 3372
diff changeset
   103
	tile2 = GetOtherShipDepotTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   105
	if (!EnsureNoVehicle(tile2)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
	if (flags & DC_EXEC) {
3373
f95cf3549591 (svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents: 3372
diff changeset
   108
		/* Kill the depot, which is registered at the northernmost tile. Use that one */
4388
e5a166837162 (svn r6141) -Codechange: introduced DepotID and used it as much as possible
truelight
parents: 4344
diff changeset
   109
		DeleteDepot(GetDepotByTile(tile2 < tile ? tile2 : tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
3111
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
   111
		MakeWater(tile);
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
   112
		MakeWater(tile2);
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
   113
		MarkTileDirtyByTile(tile);
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
   114
		MarkTileDirtyByTile(tile2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
	return _price.remove_ship_depot;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
// build a shiplift
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3111
diff changeset
   121
static int32 DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
	int32 ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
	int delta;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
	// middle tile
3491
4c8427796c64 (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
   127
	ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
2737
f16e0a808897 (svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents: 2676
diff changeset
   128
	if (CmdFailed(ret)) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   129
4559
c853d2440065 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4434
diff changeset
   130
	delta = TileOffsByDiagDir(dir);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
	// lower tile
3491
4c8427796c64 (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
   132
	ret = DoCommand(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
   133
	if (CmdFailed(ret)) return CMD_ERROR;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   134
	if (GetTileSlope(tile - delta, NULL) != SLOPE_FLAT) {
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   135
		return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   136
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
	// upper tile
3491
4c8427796c64 (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
   139
	ret = DoCommand(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
   140
	if (CmdFailed(ret)) return CMD_ERROR;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   141
	if (GetTileSlope(tile + delta, NULL) != SLOPE_FLAT) {
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   142
		return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   143
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   145
	if ((MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) ||
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   146
	    (MayHaveBridgeAbove(tile - delta) && IsBridgeAbove(tile - delta)) ||
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   147
	    (MayHaveBridgeAbove(tile + delta) && IsBridgeAbove(tile + delta))) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   148
		return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   149
	}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   150
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
	if (flags & DC_EXEC) {
3940
f3aa8e2969d4 (svn r5084) - Add owner attribute to canals and locks. This makes them more useful in multiplayer games, as before, anyone could delete any canal or lock tile. This doesn't affect whose ships can use whose canals or locks.
peter1138
parents: 3939
diff changeset
   152
		MakeLock(tile, _current_player, dir);
3372
e9eaf986b264 (svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents: 3338
diff changeset
   153
		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
   154
		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
   155
		MarkTileDirtyByTile(tile + delta);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
	return _price.clear_water * 22 >> 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   161
static int32 RemoveShiplift(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
{
4559
c853d2440065 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4434
diff changeset
   163
	TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
3940
f3aa8e2969d4 (svn r5084) - Add owner attribute to canals and locks. This makes them more useful in multiplayer games, as before, anyone could delete any canal or lock tile. This doesn't affect whose ships can use whose canals or locks.
peter1138
parents: 3939
diff changeset
   165
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
f3aa8e2969d4 (svn r5084) - Add owner attribute to canals and locks. This makes them more useful in multiplayer games, as before, anyone could delete any canal or lock tile. This doesn't affect whose ships can use whose canals or locks.
peter1138
parents: 3939
diff changeset
   166
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
	// make sure no vehicle is on the tile.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
	if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(tile + delta) || !EnsureNoVehicle(tile - delta))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
		DoClearSquare(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
		DoClearSquare(tile + delta);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
		DoClearSquare(tile - delta);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   176
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
	return _price.clear_water * 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   180
static void MarkTilesAroundDirty(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
	MarkTileDirtyByTile(TILE_ADDXY(tile, 0, 1));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	MarkTileDirtyByTile(TILE_ADDXY(tile, 0, -1));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
	MarkTileDirtyByTile(TILE_ADDXY(tile, 1, 0));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
	MarkTileDirtyByTile(TILE_ADDXY(tile, -1, 0));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
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
   188
/** Builds a lock (ship-lift)
3491
4c8427796c64 (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
   189
 * @param tile tile where to place the lock
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
   190
 * @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
   191
 * @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
   192
 */
3491
4c8427796c64 (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
   193
int32 CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
{
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3111
diff changeset
   195
	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
   196
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
   197
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3111
diff changeset
   199
	switch (GetTileSlope(tile, NULL)) {
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   200
		case SLOPE_SW: dir = DIAGDIR_SW; break;
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   201
		case SLOPE_SE: dir = DIAGDIR_SE; break;
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   202
		case SLOPE_NW: dir = DIAGDIR_NW; break;
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   203
		case SLOPE_NE: dir = DIAGDIR_NE; break;
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3111
diff changeset
   204
		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
   205
	}
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3111
diff changeset
   206
	return DoBuildShiplift(tile, dir, flags);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
1796
cae31916ae54 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   209
/** Build a piece of canal.
3491
4c8427796c64 (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
   210
 * @param tile end tile of stretch-dragging
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
   211
 * @param p1 start tile of stretch-dragging
4087
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   212
 * @param p2 ctrl pressed - toggles ocean / canals at sealevel
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
   213
 */
3491
4c8427796c64 (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
int32 CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
{
3177
b392738ba194 (svn r3813) Simplify strange control flow
tron
parents: 3165
diff changeset
   216
	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
   217
	int size_x, size_y;
3491
4c8427796c64 (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
   218
	int x;
4c8427796c64 (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
   219
	int 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
   220
	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
   221
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
   222
	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
   223
3491
4c8427796c64 (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
   224
	x = TileX(tile);
4c8427796c64 (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
   225
	y = TileY(tile);
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
   226
	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
   227
	sy = TileY(p1);
1632
c4ae19bfebf7 (svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
Darkvater
parents: 1605
diff changeset
   228
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
1632
c4ae19bfebf7 (svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
Darkvater
parents: 1605
diff changeset
   231
	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
   232
	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
   233
	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
   234
	size_y = (y - sy) + 1;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   235
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
   236
	/* 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
   237
	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
   238
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
	cost = 0;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   240
	BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   241
		int32 ret;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   242
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   243
		if (GetTileSlope(tile, NULL) != SLOPE_FLAT) {
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   244
			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   245
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
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
   247
		// can't make water of water!
4087
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   248
		if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || HASBIT(p2, 0))) 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
   249
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   250
		ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   251
		if (CmdFailed(ret)) return ret;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   252
		cost += ret;
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
   253
3189
1af302c5abd0 (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) {
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   255
			if (TileHeight(tile) == 0) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   256
				MakeWater(tile);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   257
			} else {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   258
				MakeCanal(tile, _current_player);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   259
			}
3189
1af302c5abd0 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3183
diff changeset
   260
			MarkTileDirtyByTile(tile);
1af302c5abd0 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3183
diff changeset
   261
			MarkTilesAroundDirty(tile);
1af302c5abd0 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3183
diff changeset
   262
		}
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
   263
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
		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
   265
	} END_TILE_LOOP(tile, size_x, size_y, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
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
   267
	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
   268
		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
   269
	} 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
   270
		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
   271
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   274
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
   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
	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
   277
		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
   278
			if (flags & DC_NO_WATER) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
3425
b972214fde4f (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   280
			// 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
   281
			if (!EnsureNoVehicle(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
3425
b972214fde4f (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   283
			// 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
   284
			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
   285
					!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
   286
				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
   287
			}
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
   288
3940
f3aa8e2969d4 (svn r5084) - Add owner attribute to canals and locks. This makes them more useful in multiplayer games, as before, anyone could delete any canal or lock tile. This doesn't affect whose ships can use whose canals or locks.
peter1138
parents: 3939
diff changeset
   289
			if (GetTileOwner(tile) != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR;
f3aa8e2969d4 (svn r5084) - Add owner attribute to canals and locks. This makes them more useful in multiplayer games, as before, anyone could delete any canal or lock tile. This doesn't affect whose ships can use whose canals or locks.
peter1138
parents: 3939
diff changeset
   290
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
   291
			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
   292
			return _price.clear_water;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
3439
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   294
		case WATER_COAST: {
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   295
			Slope slope = GetTileSlope(tile, NULL);
3439
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   296
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   297
			// Make sure no vehicle is on the tile
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   298
			if (!EnsureNoVehicle(tile)) return CMD_ERROR;
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   299
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   300
			// Make sure it's not an edge tile.
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   301
			if (!IS_INT_INSIDE(TileX(tile), 1, MapMaxX() - 1) ||
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   302
					!IS_INT_INSIDE(TileY(tile), 1, MapMaxY() - 1)) {
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   303
				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
   304
			}
b972214fde4f (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   305
3439
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   306
			if (flags & DC_EXEC) DoClearSquare(tile);
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   307
			if (slope == SLOPE_N || slope == SLOPE_E || slope == SLOPE_S || slope == SLOPE_W) {
3439
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   308
				return _price.clear_water;
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   309
			} else {
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   310
				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
   311
			}
3439
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   312
		}
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   313
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   314
		case WATER_LOCK: {
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   315
			static const TileIndexDiffC _shiplift_tomiddle_offs[] = {
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   316
				{ 0,  0}, {0,  0}, { 0, 0}, {0,  0}, // middle
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   317
				{-1,  0}, {0,  1}, { 1, 0}, {0, -1}, // lower
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   318
				{ 1,  0}, {0, -1}, {-1, 0}, {0,  1}, // upper
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   319
			};
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   320
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   321
			if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   322
			if (_current_player == OWNER_WATER) return CMD_ERROR;
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   323
			// move to the middle tile..
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   324
			return RemoveShiplift(tile + ToTileIndexDiff(_shiplift_tomiddle_offs[GetSection(tile)]), flags);
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   325
		}
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   326
3425
b972214fde4f (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   327
		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
   328
			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
   329
			return RemoveShipDepot(tile, flags);
3439
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   330
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   331
		default:
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   332
			NOT_REACHED();
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   333
			return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
	}
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   335
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   336
	return 0; // useless but silences warning
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
// return true if a tile is a water tile.
1048
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1041
diff changeset
   340
static bool IsWateredTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1209
diff changeset
   342
	switch (GetTileType(tile)) {
3977
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3940
diff changeset
   343
		case MP_WATER:
4087
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   344
			if (!IsCoast(tile)) return true;
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   345
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   346
			switch (GetTileSlope(tile, NULL)) {
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   347
				case SLOPE_W:
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   348
				case SLOPE_S:
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   349
				case SLOPE_E:
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   350
				case SLOPE_N:
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   351
					return true;
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   352
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   353
				default:
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   354
					return false;
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   355
			}
3977
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3940
diff changeset
   356
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   357
		case MP_STATION: return IsOilRig(tile) || IsDock(tile) || IsBuoy_(tile);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   358
		default:         return false;
1048
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1041
diff changeset
   359
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
// 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
   363
void DrawCanalWater(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
	uint wa;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   366
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
	// determine the edges around with water.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
	wa = IsWateredTile(TILE_ADDXY(tile, -1, 0)) << 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
	wa += IsWateredTile(TILE_ADDXY(tile, 0, 1)) << 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
	wa += IsWateredTile(TILE_ADDXY(tile, 1, 0)) << 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
	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
   372
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
	if (!(wa & 1)) DrawGroundSprite(SPR_CANALS_BASE + 57);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
	if (!(wa & 2)) DrawGroundSprite(SPR_CANALS_BASE + 58);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
	if (!(wa & 4)) DrawGroundSprite(SPR_CANALS_BASE + 59);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
	if (!(wa & 8)) DrawGroundSprite(SPR_CANALS_BASE + 60);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
	// right corner
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   379
	switch (wa & 0x03) {
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   380
		case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 4); break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   381
		case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 8); break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   382
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
	// bottom corner
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   385
	switch (wa & 0x06) {
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   386
		case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 5); break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   387
		case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 9); break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   388
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
	// left corner
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   391
	switch (wa & 0x0C) {
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   392
		case  0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 6); break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   393
		case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 10); break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   394
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
	// upper corner
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   397
	switch (wa & 0x09) {
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   398
		case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 7); break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   399
		case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 11); break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   400
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
typedef struct LocksDrawTileStruct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
	int8 delta_x, delta_y, delta_z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
	byte width, height, depth;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
	SpriteID image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
} LocksDrawTileStruct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
#include "table/water_land.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
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
   411
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
   412
	uint32 palette, uint base
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   413
)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
{
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   415
	DrawGroundSprite(wdts++->image);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   416
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   417
	for (; wdts->delta_x != 0x80; wdts++) {
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   418
		uint32 image = wdts->image + base;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
		if (_display_opt & DO_TRANS_BUILDINGS) {
2148
47ba4a1b1c3b (svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents: 2049
diff changeset
   420
			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
   421
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
			image |= palette;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
		AddSortableSpriteToDraw(image, ti->x + wdts->delta_x, ti->y + wdts->delta_y, wdts->width, wdts->height, wdts->unk, ti->z + wdts->delta_z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
static void DrawTile_Water(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
{
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
   430
	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
   431
		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
   432
			DrawGroundSprite(SPR_FLAT_WATER_TILE);
4087
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   433
			if (ti->z != 0 || !IsTileOwner(ti->tile, OWNER_WATER)) DrawCanalWater(ti->tile);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   434
			DrawBridgeMiddle(ti);
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
   435
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
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
   437
		case WATER_COAST:
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   438
			assert(!IsSteepSlope(ti->tileh));
5210
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 4848
diff changeset
   439
			if (_coast_base != 0) {
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 4848
diff changeset
   440
				DrawGroundSprite(_coast_base + ti->tileh);
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 4848
diff changeset
   441
			} else {
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 4848
diff changeset
   442
				DrawGroundSprite(_water_shore_sprites[ti->tileh]);
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 4848
diff changeset
   443
			}
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   444
			DrawBridgeMiddle(ti);
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
   445
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
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
   447
		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
   448
			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
   449
			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
   450
		} 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
   451
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
   452
		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
   453
			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
   454
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
void DrawShipDepotSprite(int x, int y, int image)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
{
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   460
	const WaterDrawTileStruct *wdts = _shipdepot_display_seq[image];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   462
	DrawSprite(wdts++->image, x, y);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   463
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   464
	for (; wdts->delta_x != 0x80; wdts++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
		Point pt = RemapCoords(wdts->delta_x, wdts->delta_y, wdts->delta_z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
		DrawSprite(wdts->image + PLAYER_SPRITE_COLOR(_local_player), x + pt.x, y + pt.y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4171
diff changeset
   471
static uint GetSlopeZ_Water(TileIndex tile, uint x, uint y)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   472
{
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4171
diff changeset
   473
	uint z;
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4171
diff changeset
   474
	uint tileh = GetTileSlope(tile, &z);
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4171
diff changeset
   475
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4171
diff changeset
   476
	return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   479
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
   480
{
3418
a592d40a4d04 (svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents: 3402
diff changeset
   481
	return tileh;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   482
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   483
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   484
static void GetAcceptedCargo_Water(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   489
static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
{
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
   491
	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
   492
		case WATER_CLEAR:
4087
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   493
			if (TilePixelHeight(tile) == 0 || IsTileOwner(tile, OWNER_WATER)) {
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
   494
				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
   495
			} 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
   496
				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
   497
			}
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
   498
			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
   499
		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
   500
		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
   501
		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
   502
		default: assert(0); break;
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   503
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
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
   505
	td->owner = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   508
static void AnimateTile_Water(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   513
static void TileLoopWaterHelper(TileIndex tile, const TileIndexDiffC *offs)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
{
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   515
	TileIndex target = TILE_ADD(tile, ToTileIndexDiff(offs[0]));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
	// type of this tile mustn't be water already.
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   518
	if (IsTileType(target, MP_WATER)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   520
	if (TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[1]))) != 0 ||
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   521
			TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[2]))) != 0) {
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   522
		return;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   523
	}
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   524
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   525
	if (TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[3]))) != 0 ||
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   526
			TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[4]))) != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
		// 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
   528
		switch (GetTileType(target)) {
1076
ee035f4a90e9 (svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents: 1075
diff changeset
   529
			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
   530
				TrackBits tracks;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   531
				Slope slope;
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
   532
3275
13e4aeed09b7 (svn r3987) Fix another bug in r3979 *grumble*
tron
parents: 3268
diff changeset
   533
				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
   534
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
   535
				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
   536
				slope = GetTileSlope(target, NULL);
1076
ee035f4a90e9 (svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents: 1075
diff changeset
   537
				if (!(
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   538
							(slope == SLOPE_W && tracks == TRACK_BIT_RIGHT) ||
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   539
							(slope == SLOPE_S && tracks == TRACK_BIT_UPPER) ||
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   540
							(slope == SLOPE_E && tracks == TRACK_BIT_LEFT)  ||
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   541
							(slope == SLOPE_N && tracks == TRACK_BIT_LOWER)
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
   542
						)) {
1076
ee035f4a90e9 (svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents: 1075
diff changeset
   543
					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
   544
				}
1076
ee035f4a90e9 (svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents: 1075
diff changeset
   545
			}
ee035f4a90e9 (svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents: 1075
diff changeset
   546
			/* FALLTHROUGH */
ee035f4a90e9 (svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents: 1075
diff changeset
   547
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   548
			case MP_CLEAR:
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   549
			case MP_TREES:
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   550
				_current_player = OWNER_WATER;
3491
4c8427796c64 (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
   551
				if (!CmdFailed(DoCommand(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
   552
					MakeShore(target);
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
   553
					MarkTileDirtyByTile(target);
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   554
				}
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   555
				break;
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   556
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   557
			default:
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   558
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
		_current_player = OWNER_WATER;
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   562
		{
1605
c4630be67467 (svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents: 1399
diff changeset
   563
			Vehicle *v = FindVehicleOnTileZ(target, 0);
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   564
			if (v != NULL) FloodVehicle(v);
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   565
		}
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   566
3491
4c8427796c64 (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
   567
		if (!CmdFailed(DoCommand(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
   568
			MakeWater(target);
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
   569
			MarkTileDirtyByTile(target);
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   570
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   574
static void FloodVehicle(Vehicle *v)
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   575
{
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   576
	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
   577
		uint16 pass = 0;
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   578
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
   579
		if (v->type == VEH_Road) { // flood bus/truck
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
   580
			pass = 1; // driver
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   581
			if (v->cargo_type == CT_PASSENGERS)
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   582
				pass += v->cargo_count;
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   583
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   584
			v->vehstatus |= VS_CRASHED;
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
   585
			v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 541
diff changeset
   586
			RebuildVehicleLists();
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   587
		} else if (v->type == VEH_Train) {
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4169
diff changeset
   588
			Vehicle *u;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   589
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   590
			v = GetFirstVehicleInChain(v);
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   591
			u = v;
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2657
diff changeset
   592
			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
   593
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   594
			// crash all wagons, and count passangers
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   595
			BEGIN_ENUM_WAGONS(v)
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   596
				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
   597
				v->vehstatus |= VS_CRASHED;
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   598
			END_ENUM_WAGONS(v)
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   599
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   600
			v = u;
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   601
			v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 541
diff changeset
   602
			RebuildVehicleLists();
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   603
		} else {
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   604
			return;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   605
		}
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   606
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
   607
		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
   608
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   609
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   610
		SetDParam(0, pass);
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   611
		AddNewsItem(STR_B006_FLOOD_VEHICLE_DESTROYED,
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   612
			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
   613
			v->index,
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   614
			0);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   615
		CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   616
		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
   617
	}
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   618
}
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   619
4090
0d2e6106082f (svn r5406) - Regression [r5403]: Fix assertion in TileLoop_Water() caused by oil rigs also using it...
peter1138
parents: 4087
diff changeset
   620
// called from tunnelbridge_cmd, and by TileLoop_Industry()
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   621
void TileLoop_Water(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
{
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   623
	static const TileIndexDiffC _tile_loop_offs_array[][5] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4231
diff changeset
   624
		// tile to mod              shore?    shore?
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   625
		{{-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
   626
		{{ 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
   627
		{{ 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
   628
		{{ 0, -1}, {0, 0}, {1, 0}, { 0, -1}, { 1, -1}}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
	};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
4087
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   631
	/* Ensure sea-level canals do not flood */
5590
dc34c43fc3eb (svn r7597) [cbh] - Codechange: Remove MP_TUNNELBRIDGE and introduce three new TileTypes: MP_TUNNEL, MP_STREET_BRIDGE, MP_RAILWAY_BRIDGE
celestar
parents: 5573
diff changeset
   632
	if ((IsTileType(tile, MP_WATER) || IsTileType(tile, MP_TUNNEL) ||
dc34c43fc3eb (svn r7597) [cbh] - Codechange: Remove MP_TUNNELBRIDGE and introduce three new TileTypes: MP_TUNNEL, MP_STREET_BRIDGE, MP_RAILWAY_BRIDGE
celestar
parents: 5573
diff changeset
   633
			IsTileType(tile, MP_STREET_BRIDGE) || IsTileType(tile, MP_RAILWAY_BRIDGE)) &&
4101
b4c0a3c842f8 (svn r5435) Fix (r5406): Make sure sea-level canals below bridge tiles don't flood.
peter1138
parents: 4090
diff changeset
   634
			!IsTileOwner(tile, OWNER_WATER)) return;
4087
5ae6c880d66c (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   635
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
   636
	if (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
   637
			IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) {
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   638
		uint i;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   639
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   640
		for (i = 0; i != lengthof(_tile_loop_offs_array); i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
			TileLoopWaterHelper(tile, _tile_loop_offs_array[i]);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   642
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
	}
314
a71488713a05 (svn r320) -Fix: some last _current_player fixes
truelight
parents: 222
diff changeset
   644
	// _current_player can be changed by TileLoopWaterHelper.. reset it back
a71488713a05 (svn r320) -Fix: some last _current_player fixes
truelight
parents: 222
diff changeset
   645
	//   here
a71488713a05 (svn r320) -Fix: some last _current_player fixes
truelight
parents: 222
diff changeset
   646
	_current_player = OWNER_NONE;
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   647
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   648
	// edges
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   649
	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
   650
		TileLoopWaterHelper(tile, _tile_loop_offs_array[2]);
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   651
	}
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   652
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   653
	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
   654
		TileLoopWaterHelper(tile, _tile_loop_offs_array[0]);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   655
	}
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   656
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   657
	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
   658
		TileLoopWaterHelper(tile, _tile_loop_offs_array[1]);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   659
	}
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   660
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   661
	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
   662
		TileLoopWaterHelper(tile, _tile_loop_offs_array[3]);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   663
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   666
static uint32 GetTileTrackStatus_Water(TileIndex tile, TransportType mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
{
3423
03e0e97abf41 (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
   668
	static const byte coast_tracks[] = {0, 32, 4, 0, 16, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0};
4169
b775328748af (svn r5606) Replace some magic numbers by proper TrackBits enums and macros
tron
parents: 4101
diff changeset
   669
b775328748af (svn r5606) Replace some magic numbers by proper TrackBits enums and macros
tron
parents: 4101
diff changeset
   670
	TrackBits ts;
b775328748af (svn r5606) Replace some magic numbers by proper TrackBits enums and macros
tron
parents: 4101
diff changeset
   671
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   672
	if (mode != TRANSPORT_WATER) return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
3423
03e0e97abf41 (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
   674
	switch (GetWaterTileType(tile)) {
4169
b775328748af (svn r5606) Replace some magic numbers by proper TrackBits enums and macros
tron
parents: 4101
diff changeset
   675
		case WATER_CLEAR: ts = TRACK_BIT_ALL; break;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   676
		case WATER_COAST: ts = coast_tracks[GetTileSlope(tile, NULL) & 0xF]; break;
4169
b775328748af (svn r5606) Replace some magic numbers by proper TrackBits enums and macros
tron
parents: 4101
diff changeset
   677
		case WATER_LOCK:  ts = AxisToTrackBits(DiagDirToAxis(GetLockDirection(tile))); break;
b775328748af (svn r5606) Replace some magic numbers by proper TrackBits enums and macros
tron
parents: 4101
diff changeset
   678
		case WATER_DEPOT: ts = AxisToTrackBits(GetShipDepotAxis(tile)); break;
3423
03e0e97abf41 (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
   679
		default: return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
	}
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   681
	if (TileX(tile) == 0) {
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   682
		// NE border: remove tracks that connects NE tile edge
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   683
		ts &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   684
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   685
	if (TileY(tile) == 0) {
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   686
		// NW border: remove tracks that connects NW tile edge
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   687
		ts &= ~(TRACK_BIT_Y | TRACK_BIT_LEFT | TRACK_BIT_UPPER);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   688
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   689
	return ts * 0x101;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   692
static void ClickTile_Water(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
{
3423
03e0e97abf41 (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
   694
	if (GetWaterTileType(tile) == WATER_DEPOT) {
03e0e97abf41 (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
   695
		TileIndex tile2 = GetOtherShipDepotTile(tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   696
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents: 4559
diff changeset
   697
		ShowDepotWindow(tile < tile2 ? tile : tile2, VEH_Ship);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
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
   701
static void ChangeTileOwner_Water(TileIndex tile, PlayerID old_player, PlayerID new_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
{
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
   703
	if (!IsTileOwner(tile, old_player)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
4848
56549aa3e234 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4638
diff changeset
   705
	if (new_player != PLAYER_SPECTATOR) {
1902
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
   706
		SetTileOwner(tile, new_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
	} else {
3491
4c8427796c64 (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
   708
		DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   712
static uint32 VehicleEnter_Water(Vehicle *v, TileIndex tile, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
const TileTypeProcs _tile_type_water_procs = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4231
diff changeset
   719
	DrawTile_Water,           /* draw_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4231
diff changeset
   720
	GetSlopeZ_Water,          /* get_slope_z_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4231
diff changeset
   721
	ClearTile_Water,          /* clear_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4231
diff changeset
   722
	GetAcceptedCargo_Water,   /* get_accepted_cargo_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4231
diff changeset
   723
	GetTileDesc_Water,        /* get_tile_desc_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4231
diff changeset
   724
	GetTileTrackStatus_Water, /* get_tile_track_status_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4231
diff changeset
   725
	ClickTile_Water,          /* click_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4231
diff changeset
   726
	AnimateTile_Water,        /* animate_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4231
diff changeset
   727
	TileLoop_Water,           /* tile_loop_clear */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4231
diff changeset
   728
	ChangeTileOwner_Water,    /* change_tile_owner_clear */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4231
diff changeset
   729
	NULL,                     /* get_produced_cargo_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4231
diff changeset
   730
	VehicleEnter_Water,       /* vehicle_enter_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4231
diff changeset
   731
	GetSlopeTileh_Water,      /* get_slope_tileh_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
};