src/water_cmd.cpp
author smatz
Wed, 16 Jan 2008 01:18:15 +0000
changeset 8802 e08824cdab46
parent 8775 2b4b7efc41f6
child 8813 6d054db96ede
permissions -rw-r--r--
(svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
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
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
     3
/** @file water_cmd.cpp */
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1796
diff changeset
     6
#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
     7
#include "bridge_map.h"
6486
4f8af35b11eb (svn r8908) -Codechange: declaration of DrawBridgeMiddle does not belong in a map accessors header.
rubidium
parents: 6460
diff changeset
     8
#include "bridge.h"
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6432
diff changeset
     9
#include "cmd_helper.h"
3338
2c60ed0dcce3 (svn r4120) Use the new station functions where appropriate
tron
parents: 3275
diff changeset
    10
#include "station_map.h"
8615
6b91ca653bad (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8612
diff changeset
    11
#include "tile_cmd.h"
6949
72d11a1e1e60 (svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents: 6928
diff changeset
    12
#include "landscape.h"
8720
4e60c30e2006 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8707
diff changeset
    13
#include "viewport_func.h"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8610
diff changeset
    14
#include "command_func.h"
0
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"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1214
diff changeset
    17
#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
    18
#include "vehicle_gui.h"
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2657
diff changeset
    19
#include "train.h"
7353
716c6dd9322a (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 7179
diff changeset
    20
#include "roadveh.h"
8604
8afdd9877afd (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents: 8601
diff changeset
    21
#include "water.h"
3111
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
    22
#include "water_map.h"
8003
bd88e365c18a (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7993
diff changeset
    23
#include "industry_map.h"
5210
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 4848
diff changeset
    24
#include "newgrf.h"
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
    25
#include "newgrf_canal.h"
7885
4eb9b01e37ff (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7831
diff changeset
    26
#include "misc/autoptr.hpp"
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8293
diff changeset
    27
#include "transparency.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8604
diff changeset
    28
#include "strings_func.h"
8627
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8615
diff changeset
    29
#include "functions.h"
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8615
diff changeset
    30
#include "window_func.h"
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8635
diff changeset
    31
#include "vehicle_func.h"
8653
a83f7a536919 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8640
diff changeset
    32
#include "sound_func.h"
8707
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8660
diff changeset
    33
#include "variables.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8733
diff changeset
    34
#include "player_func.h"
8766
c86cfa3a7580 (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8760
diff changeset
    35
#include "settings_type.h"
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
    36
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    37
#include "table/sprites.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    38
#include "table/strings.h"
2261
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2186
diff changeset
    39
6191
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
    40
static Vehicle *FindFloodableVehicleOnTile(TileIndex tile);
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
    41
static void FloodVehicle(Vehicle *v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
8444
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    43
/**
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    44
 * Makes a tile canal or water depending on the surroundings.
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    45
 * This as for example docks and shipdepots do not store
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    46
 * whether the tile used to be canal or 'normal' water.
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    47
 * @param t the tile to change.
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    48
 * @param o the owner of the new tile.
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    49
 */
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    50
void MakeWaterOrCanalDependingOnSurroundings(TileIndex t, Owner o)
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    51
{
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    52
	assert(GetTileSlope(t, NULL) == SLOPE_FLAT);
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    53
8518
08fc9e9bbddd (svn r11582) -Fix: tiles were not marked dirty in some cases when removing a lock
smatz
parents: 8510
diff changeset
    54
	/* Mark tile dirty in all cases */
08fc9e9bbddd (svn r11582) -Fix: tiles were not marked dirty in some cases when removing a lock
smatz
parents: 8510
diff changeset
    55
	MarkTileDirtyByTile(t);
08fc9e9bbddd (svn r11582) -Fix: tiles were not marked dirty in some cases when removing a lock
smatz
parents: 8510
diff changeset
    56
8444
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    57
	/* Non-sealevel -> canal */
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    58
	if (TileHeight(t) != 0) {
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    59
		MakeCanal(t, o);
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    60
		return;
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    61
	}
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    62
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    63
	bool has_water = false;
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    64
	bool has_canal = false;
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    65
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    66
	for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    67
		TileIndex neighbour = TileAddByDiagDir(t, dir);
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    68
		if (IsTileType(neighbour, MP_WATER)) {
8525
9d0a7c52e3ed (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8518
diff changeset
    69
			has_water |= IsSea(neighbour) || IsCoast(neighbour) || (IsShipDepot(neighbour) && GetShipDepotWaterOwner(neighbour) == OWNER_WATER);
9d0a7c52e3ed (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8518
diff changeset
    70
			has_canal |= IsCanal(neighbour) || (IsShipDepot(neighbour) && GetShipDepotWaterOwner(neighbour) != OWNER_WATER);
8444
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    71
		}
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    72
	}
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    73
	if (has_canal || !has_water) {
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    74
		MakeCanal(t, o);
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    75
	} else {
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    76
		MakeWater(t);
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    77
	}
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    78
}
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    79
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
    80
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1752
diff changeset
    81
/** 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
    82
 * @param tile tile where ship depot is built
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
    83
 * @param flags type of operation
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6432
diff changeset
    84
 * @param p1 bit 0 depot orientation (Axis)
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1752
diff changeset
    85
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7402
diff changeset
    87
CommandCost 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
    88
{
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
    89
	TileIndex tile2;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
    90
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8720
diff changeset
    91
	CommandCost ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6432
diff changeset
    93
	Axis axis = Extract<Axis, 0>(p1);
b3017e083031 (svn r8876) -Fix
tron
parents: 6432
diff changeset
    94
b3017e083031 (svn r8876) -Fix
tron
parents: 6432
diff changeset
    95
	tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
8235
fc75e5ad02b6 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 8227
diff changeset
    97
	if (!IsWaterTile(tile) || !IsWaterTile(tile2))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
		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
    99
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   100
	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
   101
8525
9d0a7c52e3ed (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8518
diff changeset
   102
	Owner o1 = GetTileOwner(tile);
9d0a7c52e3ed (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8518
diff changeset
   103
	Owner o2 = GetTileOwner(tile2);
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
   104
	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
   105
	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
   106
	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
   107
	if (CmdFailed(ret)) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   108
7885
4eb9b01e37ff (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7831
diff changeset
   109
	Depot *depot = new Depot(tile);
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1752
diff changeset
   110
	if (depot == NULL) return CMD_ERROR;
7885
4eb9b01e37ff (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7831
diff changeset
   111
	AutoPtrT<Depot> d_auto_delete = depot;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
	if (flags & DC_EXEC) {
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1214
diff changeset
   114
		depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
8525
9d0a7c52e3ed (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8518
diff changeset
   116
		MakeShipDepot(tile,  _current_player, DEPOT_NORTH, axis, o1);
9d0a7c52e3ed (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8518
diff changeset
   117
		MakeShipDepot(tile2, _current_player, DEPOT_SOUTH, axis, o2);
3372
e9eaf986b264 (svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents: 3338
diff changeset
   118
		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
   119
		MarkTileDirtyByTile(tile2);
7885
4eb9b01e37ff (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7831
diff changeset
   120
		d_auto_delete.Detach();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8720
diff changeset
   123
	return CommandCost(EXPENSES_CONSTRUCTION, _price.build_ship_depot);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
8601
6b2ddb5baade (svn r11666) -Fix (r11504): when removing buoys, return to water or canal depending on their owner
glx
parents: 8540
diff changeset
   126
void MakeWaterOrCanalDependingOnOwner(TileIndex tile, Owner o)
8525
9d0a7c52e3ed (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8518
diff changeset
   127
{
9d0a7c52e3ed (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8518
diff changeset
   128
	if (o == OWNER_WATER) {
9d0a7c52e3ed (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8518
diff changeset
   129
		MakeWater(tile);
9d0a7c52e3ed (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8518
diff changeset
   130
	} else {
9d0a7c52e3ed (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8518
diff changeset
   131
		MakeCanal(tile, o);
9d0a7c52e3ed (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8518
diff changeset
   132
	}
9d0a7c52e3ed (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8518
diff changeset
   133
}
9d0a7c52e3ed (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8518
diff changeset
   134
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7402
diff changeset
   135
static CommandCost RemoveShipDepot(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
{
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   137
	TileIndex tile2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
3373
f95cf3549591 (svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents: 3372
diff changeset
   139
	if (!IsShipDepot(tile)) return CMD_ERROR;
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   140
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
8254
5de2bbd26163 (svn r11303) -Fix: EnsureNoVehicle and EnsureNoVehicleOnGround were both used to check whether there was no vehicle on the ground, except that the former didn't take care of aircraft shadows. So now we only use EnsureNoVehicleOnGround.
rubidium
parents: 8235
diff changeset
   141
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
3373
f95cf3549591 (svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents: 3372
diff changeset
   143
	tile2 = GetOtherShipDepotTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
8254
5de2bbd26163 (svn r11303) -Fix: EnsureNoVehicle and EnsureNoVehicleOnGround were both used to check whether there was no vehicle on the ground, except that the former didn't take care of aircraft shadows. So now we only use EnsureNoVehicleOnGround.
rubidium
parents: 8235
diff changeset
   145
	if (!EnsureNoVehicleOnGround(tile2)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
	if (flags & DC_EXEC) {
3373
f95cf3549591 (svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents: 3372
diff changeset
   148
		/* Kill the depot, which is registered at the northernmost tile. Use that one */
7885
4eb9b01e37ff (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7831
diff changeset
   149
		delete GetDepotByTile(tile2 < tile ? tile2 : tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
8525
9d0a7c52e3ed (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8518
diff changeset
   151
		MakeWaterOrCanalDependingOnOwner(tile,  GetShipDepotWaterOwner(tile));
9d0a7c52e3ed (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8518
diff changeset
   152
		MakeWaterOrCanalDependingOnOwner(tile2, GetShipDepotWaterOwner(tile2));
3111
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
   153
		MarkTileDirtyByTile(tile);
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
   154
		MarkTileDirtyByTile(tile2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8720
diff changeset
   157
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_ship_depot);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   160
/** build a shiplift */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7402
diff changeset
   161
static CommandCost DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
{
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7402
diff changeset
   163
	CommandCost ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
	int delta;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   166
	/* 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
   167
	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
   168
	if (CmdFailed(ret)) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   169
4559
c853d2440065 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4434
diff changeset
   170
	delta = TileOffsByDiagDir(dir);
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   171
	/* 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
   172
	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
   173
	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
   174
	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
   175
		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
   176
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   178
	/* 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
   179
	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
   180
	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
   181
	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
   182
		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
   183
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   185
	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
   186
	    (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
   187
	    (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
   188
		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
   189
	}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   190
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
	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
   192
		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
   193
		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
   194
		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
   195
		MarkTileDirtyByTile(tile + delta);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8720
diff changeset
   198
	return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 22 >> 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7402
diff changeset
   201
static CommandCost RemoveShiplift(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
{
4559
c853d2440065 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4434
diff changeset
   203
	TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
7766
b4a38a2be0d3 (svn r10593) -Fix [FS#1038]: one could not remove locks that were build in a (very) old version of OpenTTD.
rubidium
parents: 7762
diff changeset
   205
	if (!CheckTileOwnership(tile) && GetTileOwner(tile) != OWNER_NONE) return CMD_ERROR;
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
   206
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   207
	/* make sure no vehicle is on the tile. */
8254
5de2bbd26163 (svn r11303) -Fix: EnsureNoVehicle and EnsureNoVehicleOnGround were both used to check whether there was no vehicle on the ground, except that the former didn't take care of aircraft shadows. So now we only use EnsureNoVehicleOnGround.
rubidium
parents: 8235
diff changeset
   208
	if (!EnsureNoVehicleOnGround(tile) || !EnsureNoVehicleOnGround(tile + delta) || !EnsureNoVehicleOnGround(tile - delta))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
		DoClearSquare(tile);
8444
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
   213
		MakeWaterOrCanalDependingOnSurroundings(tile + delta, _current_player);
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8424
diff changeset
   214
		MakeWaterOrCanalDependingOnSurroundings(tile - delta, _current_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   216
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8720
diff changeset
   217
	return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
8041
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8005
diff changeset
   220
/**
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8005
diff changeset
   221
 * Marks the tiles around a tile as dirty.
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8005
diff changeset
   222
 *
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8005
diff changeset
   223
 * This functions marks the tiles around a given tile as dirty for repaint.
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8005
diff changeset
   224
 *
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8005
diff changeset
   225
 * @param tile The center of the tile where all other tiles are marked as dirty
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8005
diff changeset
   226
 * @ingroup dirty
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8005
diff changeset
   227
 * @see TerraformAddDirtyTileAround
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8005
diff changeset
   228
 */
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   229
static void MarkTilesAroundDirty(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
	MarkTileDirtyByTile(TILE_ADDXY(tile, 0, 1));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
	MarkTileDirtyByTile(TILE_ADDXY(tile, 0, -1));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
	MarkTileDirtyByTile(TILE_ADDXY(tile, 1, 0));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
	MarkTileDirtyByTile(TILE_ADDXY(tile, -1, 0));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
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
   237
/** 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
   238
 * @param tile tile where to place the lock
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   239
 * @param flags type of operation
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
   240
 * @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
   241
 * @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
   242
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7402
diff changeset
   243
CommandCost 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
   244
{
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3111
diff changeset
   245
	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
   246
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3111
diff changeset
   247
	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
   248
		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
   249
		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
   250
		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
   251
		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
   252
		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
   253
	}
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3111
diff changeset
   254
	return DoBuildShiplift(tile, dir, flags);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
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
   257
/** 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
   258
 * @param tile end tile of stretch-dragging
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   259
 * @param flags type of operation
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
   260
 * @param p1 start tile of stretch-dragging
6612
b511ba22a541 (svn r9105) -Fix [FS#629]: disable the ability to make flooding water with the canal build tool. In the scenario editor you can still make both canals and flooding water at height level 0.
rubidium
parents: 6585
diff changeset
   261
 * @param p2 ctrl pressed - toggles ocean / canals at sealevel (ocean only allowed in the scenario editor)
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
   262
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7402
diff changeset
   263
CommandCost 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
   264
{
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8720
diff changeset
   265
	CommandCost cost(EXPENSES_CONSTRUCTION);
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
   266
	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
   267
	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
   268
	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
   269
	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
   270
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
   271
	if (p1 >= MapSize()) return CMD_ERROR;
6612
b511ba22a541 (svn r9105) -Fix [FS#629]: disable the ability to make flooding water with the canal build tool. In the scenario editor you can still make both canals and flooding water at height level 0.
rubidium
parents: 6585
diff changeset
   272
	/* Outside of the editor you can only build canals, not oceans */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
   273
	if (HasBit(p2, 0) && _game_mode != GM_EDITOR) 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
   274
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
   275
	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
   276
	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
   277
	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
   278
	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
   279
6432
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 6317
diff changeset
   280
	if (x < sx) Swap(x, sx);
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 6317
diff changeset
   281
	if (y < sy) Swap(y, sy);
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
   282
	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
   283
	size_y = (y - sy) + 1;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   284
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
   285
	/* 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
   286
	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
   287
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   288
	BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7402
diff changeset
   289
		CommandCost ret;
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   290
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   291
		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
   292
			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
   293
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   295
		/* can't make water of water! */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
   296
		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
   297
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   298
		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
   299
		if (CmdFailed(ret)) return ret;
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   300
		cost.AddCost(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
   301
3189
1af302c5abd0 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3183
diff changeset
   302
		if (flags & DC_EXEC) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
   303
			if (TileHeight(tile) == 0 && HasBit(p2, 0)) {
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   304
				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
   305
			} else {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   306
				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
   307
			}
3189
1af302c5abd0 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3183
diff changeset
   308
			MarkTileDirtyByTile(tile);
1af302c5abd0 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3183
diff changeset
   309
			MarkTilesAroundDirty(tile);
1af302c5abd0 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3183
diff changeset
   310
		}
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
   311
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   312
		cost.AddCost(_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
   313
	} 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
   314
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   315
	if (cost.GetCost() == 0) {
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
   316
		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
   317
	} 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
   318
		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
   319
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7402
diff changeset
   322
static CommandCost ClearTile_Water(TileIndex tile, byte flags)
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   323
{
3425
b972214fde4f (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   324
	switch (GetWaterTileType(tile)) {
6507
26c45f253d31 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6486
diff changeset
   325
		case WATER_TILE_CLEAR:
3425
b972214fde4f (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   326
			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
   327
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   328
			/* Make sure it's not an edge tile. */
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8444
diff changeset
   329
			if (!IsInsideMM(TileX(tile), 1, MapMaxX() - 1) ||
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8444
diff changeset
   330
					!IsInsideMM(TileY(tile), 1, MapMaxY() - 1)) {
3425
b972214fde4f (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   331
				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
   332
			}
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
   333
8005
9f7a95e84682 (svn r11024) -Fix [FS#1173]: give a more correct error when building some things on tile 0; "Can't build on water" or "Too close to the edge" instead of "Vehicle in the way". Patch by SmatZ.
rubidium
parents: 8003
diff changeset
   334
			/* Make sure no vehicle is on the tile */
8254
5de2bbd26163 (svn r11303) -Fix: EnsureNoVehicle and EnsureNoVehicleOnGround were both used to check whether there was no vehicle on the ground, except that the former didn't take care of aircraft shadows. So now we only use EnsureNoVehicleOnGround.
rubidium
parents: 8235
diff changeset
   335
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
8005
9f7a95e84682 (svn r11024) -Fix [FS#1173]: give a more correct error when building some things on tile 0; "Can't build on water" or "Too close to the edge" instead of "Vehicle in the way". Patch by SmatZ.
rubidium
parents: 8003
diff changeset
   336
7766
b4a38a2be0d3 (svn r10593) -Fix [FS#1038]: one could not remove locks that were build in a (very) old version of OpenTTD.
rubidium
parents: 7762
diff changeset
   337
			if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE && !CheckTileOwnership(tile)) return CMD_ERROR;
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
   338
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
   339
			if (flags & DC_EXEC) DoClearSquare(tile);
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8720
diff changeset
   340
			return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
6507
26c45f253d31 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6486
diff changeset
   342
		case WATER_TILE_COAST: {
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   343
			Slope slope = GetTileSlope(tile, NULL);
3439
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   344
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   345
			/* Make sure no vehicle is on the tile */
8254
5de2bbd26163 (svn r11303) -Fix: EnsureNoVehicle and EnsureNoVehicleOnGround were both used to check whether there was no vehicle on the ground, except that the former didn't take care of aircraft shadows. So now we only use EnsureNoVehicleOnGround.
rubidium
parents: 8235
diff changeset
   346
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
3439
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   347
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   348
			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
   349
			if (slope == SLOPE_N || slope == SLOPE_E || slope == SLOPE_S || slope == SLOPE_W) {
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8720
diff changeset
   350
				return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water);
3439
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   351
			} else {
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8720
diff changeset
   352
				return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_roughland);
3425
b972214fde4f (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   353
			}
3439
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   354
		}
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   355
6507
26c45f253d31 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6486
diff changeset
   356
		case WATER_TILE_LOCK: {
3439
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   357
			static const TileIndexDiffC _shiplift_tomiddle_offs[] = {
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   358
				{ 0,  0}, {0,  0}, { 0, 0}, {0,  0}, // middle
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   359
				{-1,  0}, {0,  1}, { 1, 0}, {0, -1}, // lower
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   360
				{ 1,  0}, {0, -1}, {-1, 0}, {0,  1}, // upper
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   361
			};
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   362
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   363
			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
   364
			if (_current_player == OWNER_WATER) return CMD_ERROR;
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   365
			/* move to the middle tile.. */
3439
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   366
			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
   367
		}
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   368
6507
26c45f253d31 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6486
diff changeset
   369
		case WATER_TILE_DEPOT:
3425
b972214fde4f (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   370
			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
   371
			return RemoveShipDepot(tile, flags);
3439
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   372
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   373
		default:
af9ed14f232c (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   374
			NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   378
/** return true if a tile is a water tile. */
1048
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1041
diff changeset
   379
static bool IsWateredTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1209
diff changeset
   381
	switch (GetTileType(tile)) {
3977
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3940
diff changeset
   382
		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
   383
			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
   384
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
   385
			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
   386
				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
   387
				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
   388
				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
   389
				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
   390
					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
   391
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
   392
				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
   393
					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
   394
			}
3977
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3940
diff changeset
   395
8770
f152783e12c3 (svn r11838) -Fix (r11320): draw correctly canal next to half flooded rail tile
smatz
parents: 8766
diff changeset
   396
		case MP_RAILWAY:  return GetRailGroundType(tile) == RAIL_GROUND_WATER;
8003
bd88e365c18a (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7993
diff changeset
   397
		case MP_STATION:  return IsOilRig(tile) || IsDock(tile) || IsBuoy(tile);
bd88e365c18a (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7993
diff changeset
   398
		case MP_INDUSTRY: return (GetIndustrySpec(GetIndustryType(tile))->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0;
bd88e365c18a (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7993
diff changeset
   399
		default:          return false;
1048
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1041
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
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   403
/** 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
   404
void DrawCanalWater(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
	uint wa;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   407
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   408
	/* Test for custom graphics, else use the default */
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   409
	SpriteID dikes_base = GetCanalSprite(CF_DIKES, tile);
8378
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8345
diff changeset
   410
	if (dikes_base == 0) dikes_base = SPR_CANAL_DIKES_BASE;
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   411
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   412
	/* determine the edges around with water. */
8003
bd88e365c18a (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7993
diff changeset
   413
	wa  = IsWateredTile(TILE_ADDXY(tile, -1,  0)) << 0;
bd88e365c18a (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7993
diff changeset
   414
	wa += IsWateredTile(TILE_ADDXY(tile,  0,  1)) << 1;
bd88e365c18a (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7993
diff changeset
   415
	wa += IsWateredTile(TILE_ADDXY(tile,  1,  0)) << 2;
bd88e365c18a (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7993
diff changeset
   416
	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
   417
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   418
	if (!(wa & 1)) DrawGroundSprite(dikes_base,     PAL_NONE);
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   419
	if (!(wa & 2)) DrawGroundSprite(dikes_base + 1, PAL_NONE);
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   420
	if (!(wa & 4)) DrawGroundSprite(dikes_base + 2, PAL_NONE);
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   421
	if (!(wa & 8)) DrawGroundSprite(dikes_base + 3, PAL_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   423
	/* right corner */
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   424
	switch (wa & 0x03) {
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   425
		case 0: DrawGroundSprite(dikes_base + 4, PAL_NONE); break;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   426
		case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(dikes_base + 8, PAL_NONE); break;
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   427
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   429
	/* bottom corner */
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   430
	switch (wa & 0x06) {
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   431
		case 0: DrawGroundSprite(dikes_base + 5, PAL_NONE); break;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   432
		case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(dikes_base + 9, PAL_NONE); break;
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   433
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   435
	/* left corner */
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   436
	switch (wa & 0x0C) {
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   437
		case  0: DrawGroundSprite(dikes_base + 6, PAL_NONE); break;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   438
		case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(dikes_base + 10, PAL_NONE); break;
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   439
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   441
	/* upper corner */
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   442
	switch (wa & 0x09) {
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   443
		case 0: DrawGroundSprite(dikes_base + 7, PAL_NONE); break;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   444
		case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(dikes_base + 11, PAL_NONE); break;
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   445
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6507
diff changeset
   448
struct LocksDrawTileStruct {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
	int8 delta_x, delta_y, delta_z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
	byte width, height, depth;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
	SpriteID image;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6507
diff changeset
   452
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
#include "table/water_land.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
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
   456
static void DrawWaterStuff(const TileInfo *ti, const WaterDrawTileStruct *wdts,
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   457
	SpriteID palette, uint base
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   458
)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
{
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   460
	SpriteID image;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   461
	SpriteID water_base = GetCanalSprite(CF_WATERSLOPE, ti->tile);
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   462
	SpriteID locks_base = GetCanalSprite(CF_LOCKS, ti->tile);
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   463
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   464
	/* If no custom graphics, use defaults */
8378
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8345
diff changeset
   465
	if (water_base == 0) water_base = SPR_CANALS_BASE;
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   466
	if (locks_base == 0) {
8378
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8345
diff changeset
   467
		locks_base = SPR_SHIPLIFT_BASE;
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   468
	} else {
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   469
		/* If using custom graphics, ignore the variation on height */
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   470
		base = 0;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   471
	}
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   472
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   473
	image = wdts++->image;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   474
	if (image < 4) image += water_base;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6987
diff changeset
   475
	DrawGroundSprite(image, PAL_NONE);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   476
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   477
	for (; wdts->delta_x != 0x80; wdts++) {
7829
88883899c9e6 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7766
diff changeset
   478
		AddSortableSpriteToDraw(wdts->image + base + ((wdts->image < 24) ? locks_base : 0), palette,
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   479
			ti->x + wdts->delta_x, ti->y + wdts->delta_y,
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   480
			wdts->width, wdts->height,
7829
88883899c9e6 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7766
diff changeset
   481
			wdts->unk, ti->z + wdts->delta_z,
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8293
diff changeset
   482
			IsTransparencySet(TO_BUILDINGS));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
}
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
static void DrawTile_Water(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
{
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
   488
	switch (GetWaterTileType(ti->tile)) {
6507
26c45f253d31 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6486
diff changeset
   489
		case WATER_TILE_CLEAR:
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   490
			DrawGroundSprite(SPR_FLAT_WATER_TILE, PAL_NONE);
8235
fc75e5ad02b6 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 8227
diff changeset
   491
			if (IsCanal(ti->tile)) 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
   492
			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
   493
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
8660
498f2a298b04 (svn r11726) -Feature[newGRF]: Extend the Action 5, feature 0D usage. Patch by BigBB
belugas
parents: 8653
diff changeset
   495
		case WATER_TILE_COAST: {
498f2a298b04 (svn r11726) -Feature[newGRF]: Extend the Action 5, feature 0D usage. Patch by BigBB
belugas
parents: 8653
diff changeset
   496
			/* Converts the enum Slope into an offset based on SPR_SHORE_BASE.
498f2a298b04 (svn r11726) -Feature[newGRF]: Extend the Action 5, feature 0D usage. Patch by BigBB
belugas
parents: 8653
diff changeset
   497
			 * This allows to calculate the proper sprite to display for this Slope */
498f2a298b04 (svn r11726) -Feature[newGRF]: Extend the Action 5, feature 0D usage. Patch by BigBB
belugas
parents: 8653
diff changeset
   498
			static const byte tileh_to_shoresprite[32] = {
498f2a298b04 (svn r11726) -Feature[newGRF]: Extend the Action 5, feature 0D usage. Patch by BigBB
belugas
parents: 8653
diff changeset
   499
				0, 1, 2, 3, 4, 16, 6, 7, 8, 9, 17, 11, 12, 13, 14, 0,
498f2a298b04 (svn r11726) -Feature[newGRF]: Extend the Action 5, feature 0D usage. Patch by BigBB
belugas
parents: 8653
diff changeset
   500
				0, 0, 0, 0, 0,  0, 0, 0, 0, 0,  0,  5,  0, 10, 15, 0,
498f2a298b04 (svn r11726) -Feature[newGRF]: Extend the Action 5, feature 0D usage. Patch by BigBB
belugas
parents: 8653
diff changeset
   501
			};
498f2a298b04 (svn r11726) -Feature[newGRF]: Extend the Action 5, feature 0D usage. Patch by BigBB
belugas
parents: 8653
diff changeset
   502
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   503
			assert(!IsSteepSlope(ti->tileh));
8660
498f2a298b04 (svn r11726) -Feature[newGRF]: Extend the Action 5, feature 0D usage. Patch by BigBB
belugas
parents: 8653
diff changeset
   504
			DrawGroundSprite(SPR_SHORE_BASE + tileh_to_shoresprite[ti->tileh], PAL_NONE);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   505
			DrawBridgeMiddle(ti);
8660
498f2a298b04 (svn r11726) -Feature[newGRF]: Extend the Action 5, feature 0D usage. Patch by BigBB
belugas
parents: 8653
diff changeset
   506
		} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
6507
26c45f253d31 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6486
diff changeset
   508
		case WATER_TILE_LOCK: {
3425
b972214fde4f (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   509
			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
   510
			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
   511
		} 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
   512
6507
26c45f253d31 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6486
diff changeset
   513
		case WATER_TILE_DEPOT:
3425
b972214fde4f (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   514
			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
   515
			break;
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
void DrawShipDepotSprite(int x, int y, int image)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
{
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   521
	const WaterDrawTileStruct *wdts = _shipdepot_display_seq[image];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   523
	DrawSprite(wdts++->image, PAL_NONE, x, y);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   524
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   525
	for (; wdts->delta_x != 0x80; wdts++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
		Point pt = RemapCoords(wdts->delta_x, wdts->delta_y, wdts->delta_z);
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   527
		DrawSprite(wdts->image, PLAYER_SPRITE_COLOR(_local_player), x + pt.x, y + pt.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4171
diff changeset
   532
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
   533
{
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4171
diff changeset
   534
	uint z;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   535
	Slope tileh = GetTileSlope(tile, &z);
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4171
diff changeset
   536
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4171
diff changeset
   537
	return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
   540
static Foundation GetFoundation_Water(TileIndex tile, Slope tileh)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   541
{
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
   542
	return FOUNDATION_NONE;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   543
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   544
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   545
static void GetAcceptedCargo_Water(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   550
static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
{
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
   552
	switch (GetWaterTileType(tile)) {
6507
26c45f253d31 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6486
diff changeset
   553
		case WATER_TILE_CLEAR:
8235
fc75e5ad02b6 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 8227
diff changeset
   554
			if (!IsCanal(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
   555
				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
   556
			} 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
   557
				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
   558
			}
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
   559
			break;
6507
26c45f253d31 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6486
diff changeset
   560
		case WATER_TILE_COAST: td->str = STR_3805_COAST_OR_RIVERBANK; break;
26c45f253d31 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6486
diff changeset
   561
		case WATER_TILE_LOCK : td->str = STR_LANDINFO_LOCK; break;
26c45f253d31 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6486
diff changeset
   562
		case WATER_TILE_DEPOT: td->str = STR_3806_SHIP_DEPOT; break;
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
   563
		default: assert(0); break;
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   564
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
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
   566
	td->owner = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   569
static void AnimateTile_Water(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
	/* not used */
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
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   574
/**
8540
ec9383f17f85 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8525
diff changeset
   575
 * Marks tile dirty if it is a canal tile.
ec9383f17f85 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8525
diff changeset
   576
 * Called to avoid glitches when flooding tiles next to canal tile.
ec9383f17f85 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8525
diff changeset
   577
 *
ec9383f17f85 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8525
diff changeset
   578
 * @param tile tile to check
ec9383f17f85 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8525
diff changeset
   579
 */
ec9383f17f85 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8525
diff changeset
   580
static inline void MarkTileDirtyIfCanal(TileIndex tile) {
ec9383f17f85 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8525
diff changeset
   581
	if (IsTileType(tile, MP_WATER) && IsCanal(tile)) MarkTileDirtyByTile(tile);
ec9383f17f85 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8525
diff changeset
   582
}
ec9383f17f85 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8525
diff changeset
   583
ec9383f17f85 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8525
diff changeset
   584
/**
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   585
 * Floods neighboured floodable tiles
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   586
 *
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   587
 * @param tile The water source tile that causes the flooding.
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   588
 * @param offs[0] Destination tile to flood.
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   589
 * @param offs[1] First corner of edge between source and dest tile.
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   590
 * @param offs[2] Second corder of edge between source and dest tile.
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   591
 * @param offs[3] Third corner of dest tile.
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   592
 * @param offs[4] Fourth corner of dest tile.
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   593
 */
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   594
static void TileLoopWaterHelper(TileIndex tile, const TileIndexDiffC *offs)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
{
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   596
	TileIndex target = TILE_ADD(tile, ToTileIndexDiff(offs[0]));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   598
	/* type of this tile mustn't be water already. */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   599
	if (IsTileType(target, MP_WATER)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   601
	/* Are both corners of the edge between source and dest on height 0 ? */
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   602
	if (TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[1]))) != 0 ||
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   603
			TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[2]))) != 0) {
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   604
		return;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   605
	}
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   606
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   607
	/* Is any corner of the dest tile raised? (First two corners already checked above. */
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   608
	if (TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[3]))) != 0 ||
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   609
			TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[4]))) != 0) {
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   610
		/* 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
   611
		switch (GetTileType(target)) {
1076
ee035f4a90e9 (svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents: 1075
diff changeset
   612
			case MP_RAILWAY: {
3275
13e4aeed09b7 (svn r3987) Fix another bug in r3979 *grumble*
tron
parents: 3268
diff changeset
   613
				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
   614
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   615
				FloodHalftile(target);
7939
ee4383a3860b (svn r10892) -Fix [FS#1127]: trains would not get flooded when they are at the lower part of a tile that would become a coast tile after flooding. Patch by frosch.
rubidium
parents: 7885
diff changeset
   616
ee4383a3860b (svn r10892) -Fix [FS#1127]: trains would not get flooded when they are at the lower part of a tile that would become a coast tile after flooding. Patch by frosch.
rubidium
parents: 7885
diff changeset
   617
				Vehicle *v = FindFloodableVehicleOnTile(target);
ee4383a3860b (svn r10892) -Fix [FS#1127]: trains would not get flooded when they are at the lower part of a tile that would become a coast tile after flooding. Patch by frosch.
rubidium
parents: 7885
diff changeset
   618
				if (v != NULL) FloodVehicle(v);
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   619
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   620
				break;
1076
ee035f4a90e9 (svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents: 1075
diff changeset
   621
			}
ee035f4a90e9 (svn r1577) Fix: [1103301] Railroad tracks on slopes weren't flooded
tron
parents: 1075
diff changeset
   622
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   623
			case MP_CLEAR:
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   624
			case MP_TREES:
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   625
				_current_player = OWNER_WATER;
7442
a4f7989f27d4 (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 7439
diff changeset
   626
				if (CmdSucceeded(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
   627
					MakeShore(target);
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
   628
					MarkTileDirtyByTile(target);
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   629
				}
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   630
				break;
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   631
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   632
			default:
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   633
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
	} else {
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   636
		/* Flood vehicles */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
		_current_player = OWNER_WATER;
6191
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   638
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   639
		Vehicle *v = FindFloodableVehicleOnTile(target);
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   640
		if (v != NULL) FloodVehicle(v);
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   641
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   642
		/* flood flat tile */
7442
a4f7989f27d4 (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 7439
diff changeset
   643
		if (CmdSucceeded(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
   644
			MakeWater(target);
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
   645
			MarkTileDirtyByTile(target);
8540
ec9383f17f85 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8525
diff changeset
   646
			/* Mark surrounding canal tiles dirty too to avoid glitches */
8775
2b4b7efc41f6 (svn r11843) -Fix: mark dirty canal tile even in diagonal direction from flooded tile
smatz
parents: 8770
diff changeset
   647
			for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
2b4b7efc41f6 (svn r11843) -Fix: mark dirty canal tile even in diagonal direction from flooded tile
smatz
parents: 8770
diff changeset
   648
				MarkTileDirtyIfCanal(target + TileOffsByDir(dir));
2b4b7efc41f6 (svn r11843) -Fix: mark dirty canal tile even in diagonal direction from flooded tile
smatz
parents: 8770
diff changeset
   649
			}
1075
ac99a44bd399 (svn r1576) Clean TileLoopWaterHelper() a bit up
tron
parents: 1048
diff changeset
   650
		}
8802
e08824cdab46 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8775
diff changeset
   651
e08824cdab46 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8775
diff changeset
   652
		/* update signals if needed */
e08824cdab46 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8775
diff changeset
   653
		UpdateSignalsInBuffer();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
6191
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   657
/**
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   658
 * Finds a vehicle to flood.
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   659
 * It does not find vehicles that are already crashed on bridges, i.e. flooded.
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   660
 * @param tile the tile where to find a vehicle to flood
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   661
 * @return a vehicle too flood or NULL when there is no vehicle too flood.
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   662
 */
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   663
static Vehicle *FindFloodableVehicleOnTile(TileIndex tile)
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   664
{
7402
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   665
	if (IsTileType(tile, MP_STATION) && IsAirport(tile)) {
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   666
		const Station *st = GetStationByTile(tile);
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   667
		const AirportFTAClass *airport = st->Airport();
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   668
		for (uint x = 0; x < airport->size_x; x++) {
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   669
			for (uint y = 0; y < airport->size_y; y++) {
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   670
				tile = TILE_ADDXY(st->airport_tile, x, y);
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   671
				Vehicle *v = FindVehicleOnTileZ(tile, 1 + airport->delta_z);
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   672
				if (v != NULL && (v->vehstatus & VS_CRASHED) == 0) return v;
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   673
			}
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   674
		}
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   675
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   676
		/* No vehicle could be flooded on this airport anymore */
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   677
		return NULL;
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   678
	}
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   679
8510
17bda703ae17 (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 8473
diff changeset
   680
	/* if non-uniform stations are disabled, flood some train in this train station (if there is any) */
17bda703ae17 (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 8473
diff changeset
   681
	if (!_patches.nonuniform_stations && IsTileType(tile, MP_STATION) && GetStationType(tile) == STATION_RAIL) {
17bda703ae17 (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 8473
diff changeset
   682
		const Station *st = GetStationByTile(tile);
17bda703ae17 (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 8473
diff changeset
   683
17bda703ae17 (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 8473
diff changeset
   684
		BEGIN_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile)
17bda703ae17 (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 8473
diff changeset
   685
			if (st->TileBelongsToRailStation(t)) {
17bda703ae17 (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 8473
diff changeset
   686
				Vehicle *v = FindVehicleOnTileZ(t, 0);
17bda703ae17 (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 8473
diff changeset
   687
				if (v != NULL && (v->vehstatus & VS_CRASHED) == 0) return v;
17bda703ae17 (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 8473
diff changeset
   688
			}
17bda703ae17 (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 8473
diff changeset
   689
		END_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile)
17bda703ae17 (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 8473
diff changeset
   690
17bda703ae17 (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 8473
diff changeset
   691
		return NULL;
17bda703ae17 (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 8473
diff changeset
   692
	}
17bda703ae17 (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 8473
diff changeset
   693
6191
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   694
	if (!IsBridgeTile(tile)) return FindVehicleOnTileZ(tile, 0);
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   695
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   696
	TileIndex end = GetOtherBridgeEnd(tile);
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   697
	byte z = GetBridgeHeight(tile);
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   698
	Vehicle *v;
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   699
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   700
	/* check the start tile first since as this is closest to the water */
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   701
	v = FindVehicleOnTileZ(tile, z);
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   702
	if (v != NULL && (v->vehstatus & VS_CRASHED) == 0) return v;
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   703
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   704
	/* check a vehicle in between both bridge heads */
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   705
	v = FindVehicleBetween(tile, end, z, true);
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   706
	if (v != NULL) return v;
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   707
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   708
	/* check the end tile last to give fleeing vehicles a chance to escape */
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   709
	v = FindVehicleOnTileZ(end, z);
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   710
	return (v != NULL && (v->vehstatus & VS_CRASHED) == 0) ? v : NULL;
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   711
}
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   712
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   713
static void FloodVehicle(Vehicle *v)
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   714
{
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   715
	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
   716
		uint16 pass = 0;
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   717
7402
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   718
		if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_AIRCRAFT) {
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   719
			if (v->type == VEH_AIRCRAFT) {
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   720
				/* Crashing aircraft are always at z_pos == 1, never on z_pos == 0,
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   721
				 * because that's always the shadow. Except for the heliport, because
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   722
				 * that station has a big z_offset for the aircraft. */
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   723
				if (!IsTileType(v->tile, MP_STATION) || !IsAirport(v->tile) || GetTileMaxZ(v->tile) != 0) return;
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   724
				const Station *st = GetStationByTile(v->tile);
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   725
				const AirportFTAClass *airport = st->Airport();
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   726
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   727
				if (v->z_pos != airport->delta_z + 1) return;
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   728
			}
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4169
diff changeset
   729
			Vehicle *u;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   730
7993
76b0eb3e19c9 (svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents: 7990
diff changeset
   731
			if (v->type != VEH_AIRCRAFT) v = v->First();
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   732
			u = v;
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   733
7353
716c6dd9322a (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 7179
diff changeset
   734
			/* crash all wagons, and count passengers */
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   735
			BEGIN_ENUM_WAGONS(v)
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7446
diff changeset
   736
				if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.Count();
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   737
				v->vehstatus |= VS_CRASHED;
6191
12d69f54e920 (svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents: 6156
diff changeset
   738
				MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   739
			END_ENUM_WAGONS(v)
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   740
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   741
			v = u;
7353
716c6dd9322a (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 7179
diff changeset
   742
7402
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   743
			switch (v->type) {
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   744
				default: NOT_REACHED();
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   745
				case VEH_TRAIN:
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   746
					if (IsFrontEngine(v)) pass += 4; // driver
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   747
					v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   748
					break;
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   749
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   750
				case VEH_ROAD:
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   751
					if (IsRoadVehFront(v)) pass += 1; // driver
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   752
					v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   753
					break;
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   754
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   755
				case VEH_AIRCRAFT:
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   756
					pass += 2; // driver
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   757
					v->u.air.crashed_counter = 9000; // max 10000, disappear pretty fast
94575d2b8b02 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 7353
diff changeset
   758
					break;
7353
716c6dd9322a (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 7179
diff changeset
   759
			}
716c6dd9322a (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 7179
diff changeset
   760
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 541
diff changeset
   761
			RebuildVehicleLists();
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   762
		} else {
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   763
			return;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   764
		}
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   765
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
   766
		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
   767
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   768
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   769
		SetDParam(0, pass);
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   770
		AddNewsItem(STR_B006_FLOOD_VEHICLE_DESTROYED,
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6949
diff changeset
   771
			NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_VEHICLE, NT_ACCIDENT, 0),
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   772
			v->index,
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   773
			0);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   774
		CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   775
		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
   776
	}
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   777
}
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   778
8227
9529f32a20fa (svn r11266) -Documentation: Add a few comments. Parts of BigBB's work on shores
belugas
parents: 8041
diff changeset
   779
/**
9529f32a20fa (svn r11266) -Documentation: Add a few comments. Parts of BigBB's work on shores
belugas
parents: 8041
diff changeset
   780
 * Let a water tile floods its diagonal adjoining tiles
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8254
diff changeset
   781
 * called from tunnelbridge_cmd, and by TileLoop_Industry() and TileLoop_Track()
8227
9529f32a20fa (svn r11266) -Documentation: Add a few comments. Parts of BigBB's work on shores
belugas
parents: 8041
diff changeset
   782
 *
9529f32a20fa (svn r11266) -Documentation: Add a few comments. Parts of BigBB's work on shores
belugas
parents: 8041
diff changeset
   783
 * @param tile the water/shore tile that floods
9529f32a20fa (svn r11266) -Documentation: Add a few comments. Parts of BigBB's work on shores
belugas
parents: 8041
diff changeset
   784
 */
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   785
void TileLoop_Water(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
{
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   787
	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
   788
		// tile to mod              shore?    shore?
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   789
		{{-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
   790
		{{ 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
   791
		{{ 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
   792
		{{ 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
   793
	};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
8235
fc75e5ad02b6 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 8227
diff changeset
   795
	/* Ensure buoys on canal borders do not flood */
fc75e5ad02b6 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 8227
diff changeset
   796
	if (IsCanalBuoyTile(tile)) return;
fc75e5ad02b6 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 8227
diff changeset
   797
	/* Ensure only sea and coast floods, not canals or rivers */
fc75e5ad02b6 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 8227
diff changeset
   798
	if (IsTileType(tile, MP_WATER) && !(IsSea(tile) || IsCoast(tile))) 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
   799
8227
9529f32a20fa (svn r11266) -Documentation: Add a few comments. Parts of BigBB's work on shores
belugas
parents: 8041
diff changeset
   800
	/* floods in all four diagonal directions with the exception of the edges */
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8444
diff changeset
   801
	if (IsInsideMM(TileX(tile), 1, MapSizeX() - 3 + 1) &&
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8444
diff changeset
   802
			IsInsideMM(TileY(tile), 1, MapSizeY() - 3 + 1)) {
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   803
		uint i;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   804
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   805
		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
   806
			TileLoopWaterHelper(tile, _tile_loop_offs_array[i]);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   807
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
	}
8227
9529f32a20fa (svn r11266) -Documentation: Add a few comments. Parts of BigBB's work on shores
belugas
parents: 8041
diff changeset
   809
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   810
	/* _current_player can be changed by TileLoopWaterHelper.. reset it back here */
314
a71488713a05 (svn r320) -Fix: some last _current_player fixes
truelight
parents: 222
diff changeset
   811
	_current_player = OWNER_NONE;
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   812
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   813
	/* edges */
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8444
diff changeset
   814
	if (TileX(tile) == 0 && IsInsideMM(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
   815
		TileLoopWaterHelper(tile, _tile_loop_offs_array[2]);
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   816
	}
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   817
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8444
diff changeset
   818
	if (TileX(tile) == MapSizeX() - 2 && IsInsideMM(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
   819
		TileLoopWaterHelper(tile, _tile_loop_offs_array[0]);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   820
	}
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   821
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8444
diff changeset
   822
	if (TileY(tile) == 0 && IsInsideMM(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
   823
		TileLoopWaterHelper(tile, _tile_loop_offs_array[1]);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   824
	}
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   825
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8444
diff changeset
   826
	if (TileY(tile) == MapSizeY() - 2 && IsInsideMM(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
   827
		TileLoopWaterHelper(tile, _tile_loop_offs_array[3]);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   828
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
7179
3e123c2b7c93 (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 7079
diff changeset
   831
static uint32 GetTileTrackStatus_Water(TileIndex tile, TransportType mode, uint sub_mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
{
3423
03e0e97abf41 (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
   833
	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
   834
b775328748af (svn r5606) Replace some magic numbers by proper TrackBits enums and macros
tron
parents: 4101
diff changeset
   835
	TrackBits ts;
b775328748af (svn r5606) Replace some magic numbers by proper TrackBits enums and macros
tron
parents: 4101
diff changeset
   836
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   837
	if (mode != TRANSPORT_WATER) return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
3423
03e0e97abf41 (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
   839
	switch (GetWaterTileType(tile)) {
6507
26c45f253d31 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6486
diff changeset
   840
		case WATER_TILE_CLEAR: ts = TRACK_BIT_ALL; break;
26c45f253d31 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6486
diff changeset
   841
		case WATER_TILE_COAST: ts = (TrackBits)coast_tracks[GetTileSlope(tile, NULL) & 0xF]; break;
26c45f253d31 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6486
diff changeset
   842
		case WATER_TILE_LOCK:  ts = AxisToTrackBits(DiagDirToAxis(GetLockDirection(tile))); break;
26c45f253d31 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6486
diff changeset
   843
		case WATER_TILE_DEPOT: ts = AxisToTrackBits(GetShipDepotAxis(tile)); break;
3423
03e0e97abf41 (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
   844
		default: return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
	}
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   846
	if (TileX(tile) == 0) {
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   847
		/* NE border: remove tracks that connects NE tile edge */
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   848
		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
   849
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   850
	if (TileY(tile) == 0) {
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   851
		/* NW border: remove tracks that connects NW tile edge */
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   852
		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
   853
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   854
	return ts * 0x101;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   857
static void ClickTile_Water(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
{
6507
26c45f253d31 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6486
diff changeset
   859
	if (GetWaterTileType(tile) == WATER_TILE_DEPOT) {
3423
03e0e97abf41 (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
   860
		TileIndex tile2 = GetOtherShipDepotTile(tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   861
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   862
		ShowDepotWindow(tile < tile2 ? tile : tile2, VEH_SHIP);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
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
   866
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
   867
{
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
   868
	if (!IsTileOwner(tile, old_player)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
4848
56549aa3e234 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4638
diff changeset
   870
	if (new_player != PLAYER_SPECTATOR) {
1902
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
   871
		SetTileOwner(tile, new_player);
7766
b4a38a2be0d3 (svn r10593) -Fix [FS#1038]: one could not remove locks that were build in a (very) old version of OpenTTD.
rubidium
parents: 7762
diff changeset
   872
	} else if (IsShipDepot(tile)) {
b4a38a2be0d3 (svn r10593) -Fix [FS#1038]: one could not remove locks that were build in a (very) old version of OpenTTD.
rubidium
parents: 7762
diff changeset
   873
		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
   874
	} else {
7766
b4a38a2be0d3 (svn r10593) -Fix [FS#1038]: one could not remove locks that were build in a (very) old version of OpenTTD.
rubidium
parents: 7762
diff changeset
   875
		SetTileOwner(tile, OWNER_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
8615
6b91ca653bad (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8612
diff changeset
   879
static VehicleEnterTileStatus 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
   880
{
6317
c73bda71ac16 (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 6205
diff changeset
   881
	return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7939
diff changeset
   884
static CommandCost TerraformTile_Water(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7939
diff changeset
   885
{
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7939
diff changeset
   886
	/* Canals can't be terraformed */
8235
fc75e5ad02b6 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 8227
diff changeset
   887
	if (IsWaterTile(tile) && IsCanal(tile)) return_cmd_error(STR_MUST_DEMOLISH_CANAL_FIRST);
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7939
diff changeset
   888
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7939
diff changeset
   889
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7939
diff changeset
   890
}
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7939
diff changeset
   891
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   893
extern 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
   894
	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
   895
	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
   896
	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
   897
	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
   898
	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
   899
	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
   900
	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
   901
	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
   902
	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
   903
	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
   904
	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
   905
	VehicleEnter_Water,       /* vehicle_enter_tile_proc */
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
   906
	GetFoundation_Water,      /* get_foundation_proc */
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7939
diff changeset
   907
	TerraformTile_Water,      /* terraform_tile_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
};