src/water_cmd.cpp
author terom@frrb.lan
Fri, 19 Dec 2008 01:32:07 +0200
changeset 10438 51bff16a04c9
parent 10236 50afe9dd466e
permissions -rw-r--r--
initial mini-map stuff
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9038
diff changeset
     3
/** @file water_cmd.cpp Handling of water tiles. */
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1796
diff changeset
     6
#include "openttd.h"
3189
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3183
diff changeset
     7
#include "bridge_map.h"
6160
fa42299e967e (svn r8908) -Codechange: declaration of DrawBridgeMiddle does not belong in a map accessors header.
rubidium
parents: 6134
diff changeset
     8
#include "bridge.h"
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6106
diff changeset
     9
#include "cmd_helper.h"
3338
7cff208f0446 (svn r4120) Use the new station functions where appropriate
tron
parents: 3275
diff changeset
    10
#include "station_map.h"
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8116
diff changeset
    11
#include "tile_cmd.h"
6453
226bcddeba32 (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: 6432
diff changeset
    12
#include "landscape.h"
8224
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8211
diff changeset
    13
#include "viewport_func.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
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"
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8684
diff changeset
    16
#include "news_func.h"
8962
1b263c69799d (svn r12754) -Codechange: split depot.h into depot_map.h, depot_func.h and depot_base.h and remove quite a lot of unneeded (before this) includes of depot.h.
rubidium
parents: 8806
diff changeset
    17
#include "depot_base.h"
1b263c69799d (svn r12754) -Codechange: split depot.h into depot_map.h, depot_func.h and depot_base.h and remove quite a lot of unneeded (before this) includes of depot.h.
rubidium
parents: 8806
diff changeset
    18
#include "depot_func.h"
1752
d65cd19f7117 (svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents: 1632
diff changeset
    19
#include "vehicle_gui.h"
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2657
diff changeset
    20
#include "train.h"
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6683
diff changeset
    21
#include "roadveh.h"
8108
b42a0e5c67ef (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents: 8105
diff changeset
    22
#include "water.h"
3111
750f37699a13 (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
    23
#include "water_map.h"
7507
36bb5300a128 (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7497
diff changeset
    24
#include "industry_map.h"
5210
3415ef43c70a (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 4848
diff changeset
    25
#include "newgrf.h"
6583
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
    26
#include "newgrf_canal.h"
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7797
diff changeset
    27
#include "transparency.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8108
diff changeset
    28
#include "strings_func.h"
8131
160939e24ed3 (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: 8119
diff changeset
    29
#include "functions.h"
160939e24ed3 (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: 8119
diff changeset
    30
#include "window_func.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8139
diff changeset
    31
#include "vehicle_func.h"
8157
1505def01945 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8144
diff changeset
    32
#include "sound_func.h"
8211
29a8510dfd62 (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8164
diff changeset
    33
#include "variables.h"
10208
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    34
#include "company_func.h"
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8264
diff changeset
    35
#include "settings_type.h"
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    36
#include "clear_map.h"
8459
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
    37
#include "tree_map.h"
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8763
diff changeset
    38
#include "station_base.h"
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8763
diff changeset
    39
#include "airport.h"
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
    40
#include "aircraft.h"
8787
41d9d5adbe87 (svn r12495) -Codechange: reduce the dependency on newgrf_station.h (especially because newgrf_station.h includes a lot of stuff).
rubidium
parents: 8785
diff changeset
    41
#include "newgrf_cargo.h"
9009
6684576ef32b (svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium
parents: 8962
diff changeset
    42
#include "effectvehicle_func.h"
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9036
diff changeset
    43
#include "oldpool_func.h"
9490
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
    44
#include "tunnelbridge_map.h"
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
    45
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    46
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    47
#include "table/strings.h"
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2186
diff changeset
    48
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    49
/**
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    50
 * Describes the behaviour of a tile during flooding.
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    51
 */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    52
enum FloodingBehaviour {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    53
	FLOOD_NONE,    ///< The tile does not flood neighboured tiles.
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    54
	FLOOD_ACTIVE,  ///< The tile floods neighboured tiles.
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    55
	FLOOD_PASSIVE, ///< The tile does not actively flood neighboured tiles, but it prevents them from drying up.
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    56
	FLOOD_DRYUP,   ///< The tile drys up if it is not constantly flooded from neighboured tiles.
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    57
};
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    58
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    59
/**
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    60
 * Describes from which directions a specific slope can be flooded (if the tile is floodable at all).
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    61
 */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    62
static const uint8 _flood_from_dirs[] = {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    63
	(1 << DIR_NW) | (1 << DIR_SW) | (1 << DIR_SE) | (1 << DIR_NE), // SLOPE_FLAT
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    64
	(1 << DIR_NE) | (1 << DIR_SE),                                 // SLOPE_W
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    65
	(1 << DIR_NW) | (1 << DIR_NE),                                 // SLOPE_S
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    66
	(1 << DIR_NE),                                                 // SLOPE_SW
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    67
	(1 << DIR_NW) | (1 << DIR_SW),                                 // SLOPE_E
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    68
	0,                                                             // SLOPE_EW
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    69
	(1 << DIR_NW),                                                 // SLOPE_SE
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    70
	(1 << DIR_N ) | (1 << DIR_NW) | (1 << DIR_NE),                 // SLOPE_WSE, SLOPE_STEEP_S
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    71
	(1 << DIR_SW) | (1 << DIR_SE),                                 // SLOPE_N
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    72
	(1 << DIR_SE),                                                 // SLOPE_NW
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    73
	0,                                                             // SLOPE_NS
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    74
	(1 << DIR_E ) | (1 << DIR_NE) | (1 << DIR_SE),                 // SLOPE_NWS, SLOPE_STEEP_W
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    75
	(1 << DIR_SW),                                                 // SLOPE_NE
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    76
	(1 << DIR_S ) | (1 << DIR_SW) | (1 << DIR_SE),                 // SLOPE_ENW, SLOPE_STEEP_N
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    77
	(1 << DIR_W ) | (1 << DIR_SW) | (1 << DIR_NW),                 // SLOPE_SEN, SLOPE_STEEP_E
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    78
};
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    79
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    80
/**
8443
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    81
 * Marks tile dirty if it is a canal or river tile.
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    82
 * Called to avoid glitches when flooding tiles next to canal tile.
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    83
 *
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    84
 * @param tile tile to check
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    85
 */
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    86
static inline void MarkTileDirtyIfCanalOrRiver(TileIndex tile)
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    87
{
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    88
	if (IsTileType(tile, MP_WATER) && (IsCanal(tile) || IsRiver(tile))) MarkTileDirtyByTile(tile);
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    89
}
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    90
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    91
/**
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    92
 * Marks the tiles around a tile as dirty, if they are canals or rivers.
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    93
 *
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    94
 * @param tile The center of the tile where all other tiles are marked as dirty
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    95
 * @ingroup dirty
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    96
 */
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    97
static void MarkCanalsAndRiversAroundDirty(TileIndex tile)
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    98
{
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
    99
	for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   100
		MarkTileDirtyIfCanalOrRiver(tile + TileOffsByDir(dir));
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   101
	}
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   102
}
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   103
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   104
/**
7948
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   105
 * Makes a tile canal or water depending on the surroundings.
8495
35c77bdca32a (svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
frosch
parents: 8471
diff changeset
   106
 *
35c77bdca32a (svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
frosch
parents: 8471
diff changeset
   107
 * Must only be used for converting old savegames. Use WaterClass now.
35c77bdca32a (svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
frosch
parents: 8471
diff changeset
   108
 *
7948
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   109
 * This as for example docks and shipdepots do not store
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   110
 * whether the tile used to be canal or 'normal' water.
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   111
 * @param t the tile to change.
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   112
 * @param o the owner of the new tile.
9718
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   113
 * @param include_invalid_water_class Also consider WATER_CLASS_INVALID, i.e. industry tiles on land
7948
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   114
 */
9718
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   115
void SetWaterClassDependingOnSurroundings(TileIndex t, bool include_invalid_water_class)
7948
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   116
{
9718
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   117
	/* If the slope is not flat, we always assume 'land' (if allowed). Also for one-corner-raised-shores.
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   118
	 * Note: Wrt. autosloping under industry tiles this is the most fool-proof behaviour. */
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   119
	if (GetTileSlope(t, NULL) != SLOPE_FLAT) {
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   120
		if (include_invalid_water_class) {
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   121
			SetWaterClass(t, WATER_CLASS_INVALID);
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   122
			return;
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   123
		} else {
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   124
			NOT_REACHED();
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   125
		}
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   126
	}
7948
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   127
8022
3b4f24a14ace (svn r11582) -Fix: tiles were not marked dirty in some cases when removing a lock
smatz
parents: 8014
diff changeset
   128
	/* Mark tile dirty in all cases */
3b4f24a14ace (svn r11582) -Fix: tiles were not marked dirty in some cases when removing a lock
smatz
parents: 8014
diff changeset
   129
	MarkTileDirtyByTile(t);
3b4f24a14ace (svn r11582) -Fix: tiles were not marked dirty in some cases when removing a lock
smatz
parents: 8014
diff changeset
   130
8526
2c0a12f36f25 (svn r12101) -Fix (r12100): there are void tiles at MapMaxX,Y - have to substract one to be on water border tiles
smatz
parents: 8525
diff changeset
   131
	if (TileX(t) == 0 || TileY(t) == 0 || TileX(t) == MapMaxX() - 1 || TileY(t) == MapMaxY() - 1) {
8525
2670d1ad818c (svn r12100) -Fix (r12042): check for water class of surrounding tiles fails for buoys at map borders
smatz
parents: 8520
diff changeset
   132
		/* tiles at map borders are always WATER_CLASS_SEA */
2670d1ad818c (svn r12100) -Fix (r12042): check for water class of surrounding tiles fails for buoys at map borders
smatz
parents: 8520
diff changeset
   133
		SetWaterClass(t, WATER_CLASS_SEA);
2670d1ad818c (svn r12100) -Fix (r12042): check for water class of surrounding tiles fails for buoys at map borders
smatz
parents: 8520
diff changeset
   134
		return;
2670d1ad818c (svn r12100) -Fix (r12042): check for water class of surrounding tiles fails for buoys at map borders
smatz
parents: 8520
diff changeset
   135
	}
2670d1ad818c (svn r12100) -Fix (r12042): check for water class of surrounding tiles fails for buoys at map borders
smatz
parents: 8520
diff changeset
   136
7948
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   137
	bool has_water = false;
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   138
	bool has_canal = false;
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   139
	bool has_river = false;
7948
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   140
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   141
	for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   142
		TileIndex neighbour = TileAddByDiagDir(t, dir);
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   143
		switch (GetTileType(neighbour)) {
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   144
			case MP_WATER:
8495
35c77bdca32a (svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
frosch
parents: 8471
diff changeset
   145
				/* clear water and shipdepots have already a WaterClass associated */
35c77bdca32a (svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
frosch
parents: 8471
diff changeset
   146
				if (IsCoast(neighbour)) {
35c77bdca32a (svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
frosch
parents: 8471
diff changeset
   147
					has_water = true;
35c77bdca32a (svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
frosch
parents: 8471
diff changeset
   148
				} else if (!IsLock(neighbour)) {
35c77bdca32a (svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
frosch
parents: 8471
diff changeset
   149
					switch (GetWaterClass(neighbour)) {
35c77bdca32a (svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
frosch
parents: 8471
diff changeset
   150
						case WATER_CLASS_SEA:   has_water = true; break;
35c77bdca32a (svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
frosch
parents: 8471
diff changeset
   151
						case WATER_CLASS_CANAL: has_canal = true; break;
35c77bdca32a (svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
frosch
parents: 8471
diff changeset
   152
						case WATER_CLASS_RIVER: has_river = true; break;
35c77bdca32a (svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
frosch
parents: 8471
diff changeset
   153
						default: NOT_REACHED();
35c77bdca32a (svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
frosch
parents: 8471
diff changeset
   154
					}
35c77bdca32a (svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
frosch
parents: 8471
diff changeset
   155
				}
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   156
				break;
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   157
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   158
			case MP_RAILWAY:
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   159
				/* Shore or flooded halftile */
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   160
				has_water |= (GetRailGroundType(neighbour) == RAIL_GROUND_WATER);
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   161
				break;
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   162
8459
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
   163
			case MP_TREES:
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
   164
				/* trees on shore */
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
   165
				has_water |= (GetTreeGround(neighbour) == TREE_GROUND_SHORE);
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
   166
				break;
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
   167
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   168
			default: break;
7948
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   169
		}
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   170
	}
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   171
9718
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   172
	if (!has_water && !has_canal && !has_river && include_invalid_water_class) {
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   173
		SetWaterClass(t, WATER_CLASS_INVALID);
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   174
		return;
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   175
	}
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   176
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   177
	if (has_river && !has_canal) {
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   178
		SetWaterClass(t, WATER_CLASS_RIVER);
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   179
	} else if (has_canal || !has_water) {
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   180
		SetWaterClass(t, WATER_CLASS_CANAL);
7948
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   181
	} else {
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   182
		SetWaterClass(t, WATER_CLASS_SEA);
7948
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   183
	}
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   184
}
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   185
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7928
diff changeset
   186
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1752
diff changeset
   187
/** Build a ship depot.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3439
diff changeset
   188
 * @param tile tile where ship depot is built
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   189
 * @param flags type of operation
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6106
diff changeset
   190
 * @param p1 bit 0 depot orientation (Axis)
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1752
diff changeset
   191
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   193
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
   194
{
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3439
diff changeset
   195
	TileIndex tile2;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   196
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   197
	CommandCost ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6106
diff changeset
   199
	Axis axis = Extract<Axis, 0>(p1);
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6106
diff changeset
   200
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6106
diff changeset
   201
	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
   202
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   203
	if (!IsWaterTile(tile) || !IsWaterTile(tile2)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
		return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER);
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   205
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   207
	if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   208
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   209
	if (GetTileSlope(tile, NULL) != SLOPE_FLAT || GetTileSlope(tile2, NULL) != SLOPE_FLAT) {
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   210
		/* Prevent depots on rapids */
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   211
		return_cmd_error(STR_0239_SITE_UNSUITABLE);
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   212
	}
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   213
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   214
	WaterClass wc1 = GetWaterClass(tile);
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   215
	WaterClass wc2 = GetWaterClass(tile2);
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3439
diff changeset
   216
	ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1752
diff changeset
   217
	if (CmdFailed(ret)) return CMD_ERROR;
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3439
diff changeset
   218
	ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1752
diff changeset
   219
	if (CmdFailed(ret)) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   220
9036
6368fe55fd6d (svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents: 9009
diff changeset
   221
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
	if (flags & DC_EXEC) {
9036
6368fe55fd6d (svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents: 9009
diff changeset
   224
		Depot *depot = new Depot(tile);
10236
50afe9dd466e (svn r14464) -Codechange: replace (uint)-1 with UINT_MAX (PhilSophus)
rubidium
parents: 10208
diff changeset
   225
		depot->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10083
diff changeset
   227
		MakeShipDepot(tile,  _current_company, DEPOT_NORTH, axis, wc1);
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10083
diff changeset
   228
		MakeShipDepot(tile2, _current_company, DEPOT_SOUTH, axis, wc2);
3372
f6afa98d5219 (svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents: 3338
diff changeset
   229
		MarkTileDirtyByTile(tile);
f6afa98d5219 (svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents: 3338
diff changeset
   230
		MarkTileDirtyByTile(tile2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   233
	return CommandCost(EXPENSES_CONSTRUCTION, _price.build_ship_depot);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   236
void MakeWaterKeepingClass(TileIndex tile, Owner o)
8029
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8022
diff changeset
   237
{
9718
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   238
	assert(IsTileType(tile, MP_WATER) || (IsTileType(tile, MP_STATION) && (IsBuoy(tile) || IsDock(tile) || IsOilRig(tile))) || IsTileType(tile, MP_INDUSTRY));
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   239
9718
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   240
	WaterClass wc = GetWaterClass(tile);
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   241
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   242
	/* Autoslope might turn an originally canal or river tile into land */
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   243
	uint z;
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   244
	if (GetTileSlope(tile, &z) != SLOPE_FLAT) wc = WATER_CLASS_INVALID;
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   245
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   246
	if (wc == WATER_CLASS_SEA && z > 0) wc = WATER_CLASS_CANAL;
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   247
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   248
	switch (wc) {
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   249
		case WATER_CLASS_SEA:   MakeWater(tile);              break;
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   250
		case WATER_CLASS_CANAL: MakeCanal(tile, o, Random()); break;
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   251
		case WATER_CLASS_RIVER: MakeRiver(tile, Random());    break;
9718
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   252
		default:                DoClearSquare(tile);          break;
8029
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8022
diff changeset
   253
	}
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8022
diff changeset
   254
}
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8022
diff changeset
   255
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   256
static CommandCost RemoveShipDepot(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
{
3373
2838aadd3a28 (svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents: 3372
diff changeset
   258
	if (!IsShipDepot(tile)) return CMD_ERROR;
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   259
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
8520
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
   261
	TileIndex tile2 = GetOtherShipDepotTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
8520
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
   263
	/* do not check for ship on tile when company goes bankrupt */
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
   264
	if (!(flags & DC_BANKRUPT)) {
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
   265
		if (!EnsureNoVehicleOnGround(tile) || !EnsureNoVehicleOnGround(tile2)) return CMD_ERROR;
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
   266
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
	if (flags & DC_EXEC) {
3373
2838aadd3a28 (svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents: 3372
diff changeset
   269
		/* Kill the depot, which is registered at the northernmost tile. Use that one */
7389
08d6a6265ced (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7335
diff changeset
   270
		delete GetDepotByTile(tile2 < tile ? tile2 : tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
8495
35c77bdca32a (svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
frosch
parents: 8471
diff changeset
   272
		MakeWaterKeepingClass(tile,  GetTileOwner(tile));
35c77bdca32a (svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
frosch
parents: 8471
diff changeset
   273
		MakeWaterKeepingClass(tile2, GetTileOwner(tile2));
3111
750f37699a13 (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
   274
		MarkTileDirtyByTile(tile);
750f37699a13 (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
   275
		MarkTileDirtyByTile(tile2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   278
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_ship_depot);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   281
/** build a shiplift */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   282
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
   283
{
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   284
	CommandCost ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
	int delta;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   287
	/* middle tile */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3439
diff changeset
   288
	ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
2737
fb1556b8f5e0 (svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents: 2676
diff changeset
   289
	if (CmdFailed(ret)) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   290
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4434
diff changeset
   291
	delta = TileOffsByDiagDir(dir);
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   292
	/* lower tile */
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   293
	WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WATER_CLASS_CANAL;
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   294
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3439
diff changeset
   295
	ret = DoCommand(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
2737
fb1556b8f5e0 (svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents: 2676
diff changeset
   296
	if (CmdFailed(ret)) return CMD_ERROR;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   297
	if (GetTileSlope(tile - delta, NULL) != SLOPE_FLAT) {
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   298
		return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   299
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   301
	/* upper tile */
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   302
	WaterClass wc_upper = IsWaterTile(tile + delta) ? GetWaterClass(tile + delta) : WATER_CLASS_CANAL;
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   303
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3439
diff changeset
   304
	ret = DoCommand(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
2737
fb1556b8f5e0 (svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents: 2676
diff changeset
   305
	if (CmdFailed(ret)) return CMD_ERROR;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   306
	if (GetTileSlope(tile + delta, NULL) != SLOPE_FLAT) {
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   307
		return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   308
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   310
	if ((MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) ||
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   311
	    (MayHaveBridgeAbove(tile - delta) && IsBridgeAbove(tile - delta)) ||
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   312
	    (MayHaveBridgeAbove(tile + delta) && IsBridgeAbove(tile + delta))) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   313
		return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   314
	}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   315
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
	if (flags & DC_EXEC) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10083
diff changeset
   317
		MakeLock(tile, _current_company, dir, wc_lower, wc_upper);
3372
f6afa98d5219 (svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents: 3338
diff changeset
   318
		MarkTileDirtyByTile(tile);
f6afa98d5219 (svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents: 3338
diff changeset
   319
		MarkTileDirtyByTile(tile - delta);
f6afa98d5219 (svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents: 3338
diff changeset
   320
		MarkTileDirtyByTile(tile + delta);
8443
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   321
		MarkCanalsAndRiversAroundDirty(tile - delta);
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   322
		MarkCanalsAndRiversAroundDirty(tile + delta);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   325
	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
   326
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   328
static CommandCost RemoveShiplift(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
{
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4434
diff changeset
   330
	TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
7270
7bbf428c2ead (svn r10593) -Fix [FS#1038]: one could not remove locks that were build in a (very) old version of OpenTTD.
rubidium
parents: 7266
diff changeset
   332
	if (!CheckTileOwnership(tile) && GetTileOwner(tile) != OWNER_NONE) return CMD_ERROR;
3940
8965b9bfaabc (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
   333
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   334
	/* make sure no vehicle is on the tile. */
7758
17ad53748c7b (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: 7739
diff changeset
   335
	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
   336
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
		DoClearSquare(tile);
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   340
		MakeWaterKeepingClass(tile + delta, GetTileOwner(tile));
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   341
		MakeWaterKeepingClass(tile - delta, GetTileOwner(tile));
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   342
		MarkTileDirtyByTile(tile - delta);
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   343
		MarkTileDirtyByTile(tile + delta);
8443
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   344
		MarkCanalsAndRiversAroundDirty(tile - delta);
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   345
		MarkCanalsAndRiversAroundDirty(tile + delta);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   347
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   348
	return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   351
/** Builds a lock (ship-lift)
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3439
diff changeset
   352
 * @param tile tile where to place the lock
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   353
 * @param flags type of operation
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   354
 * @param p1 unused
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   355
 * @param p2 unused
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   356
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   357
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
   358
{
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8386
diff changeset
   359
	DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile, NULL));
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8386
diff changeset
   360
	if (dir == INVALID_DIAGDIR) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
8386
bed99ec71cb0 (svn r11956) -Fix [FS#1675]: Disallow building locks and docks on rapids.
peter1138
parents: 8380
diff changeset
   361
bed99ec71cb0 (svn r11956) -Fix [FS#1675]: Disallow building locks and docks on rapids.
peter1138
parents: 8380
diff changeset
   362
	/* Disallow building of locks on river rapids */
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   363
	if (IsWaterTile(tile)) return_cmd_error(STR_0239_SITE_UNSUITABLE);
8386
bed99ec71cb0 (svn r11956) -Fix [FS#1675]: Disallow building locks and docks on rapids.
peter1138
parents: 8380
diff changeset
   364
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3111
diff changeset
   365
	return DoBuildShiplift(tile, dir, flags);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   368
/** Build a piece of canal.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3439
diff changeset
   369
 * @param tile end tile of stretch-dragging
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   370
 * @param flags type of operation
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   371
 * @param p1 start tile of stretch-dragging
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8386
diff changeset
   372
 * @param p2 specifies canal (0), water (1) or river (2); last two can only be built in scenario editor
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   373
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   374
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
   375
{
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   376
	CommandCost cost(EXPENSES_CONSTRUCTION);
1632
10c391e108b7 (svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
Darkvater
parents: 1605
diff changeset
   377
	int size_x, size_y;
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3439
diff changeset
   378
	int x;
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3439
diff changeset
   379
	int y;
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   380
	int sx, sy;
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   381
2934
3f29a7212713 (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents: 2737
diff changeset
   382
	if (p1 >= MapSize()) return CMD_ERROR;
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   383
6286
a67f2c376804 (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: 6259
diff changeset
   384
	/* Outside of the editor you can only build canals, not oceans */
8361
7963f4b11d96 (svn r11927) -Fix (r11926): unable to place canals in game
peter1138
parents: 8360
diff changeset
   385
	if (p2 != 0 && _game_mode != GM_EDITOR) return CMD_ERROR;
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   386
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3439
diff changeset
   387
	x = TileX(tile);
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3439
diff changeset
   388
	y = TileY(tile);
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   389
	sx = TileX(p1);
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   390
	sy = TileY(p1);
1632
10c391e108b7 (svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
Darkvater
parents: 1605
diff changeset
   391
6106
2898cd9417fd (svn r8841) -Fix
tron
parents: 5991
diff changeset
   392
	if (x < sx) Swap(x, sx);
2898cd9417fd (svn r8841) -Fix
tron
parents: 5991
diff changeset
   393
	if (y < sy) Swap(y, sy);
1632
10c391e108b7 (svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
Darkvater
parents: 1605
diff changeset
   394
	size_x = (x - sx) + 1;
10c391e108b7 (svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
Darkvater
parents: 1605
diff changeset
   395
	size_y = (y - sy) + 1;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   396
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   397
	/* Outside the editor you can only drag canals, and not areas */
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   398
	if (_game_mode != GM_EDITOR && (sx != x && sy != y)) return CMD_ERROR;
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   399
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   400
	BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   401
		CommandCost ret;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   402
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   403
		Slope slope = GetTileSlope(tile, NULL);
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8386
diff changeset
   404
		if (slope != SLOPE_FLAT && (p2 != 2 || !IsInclinedSlope(slope))) {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   405
			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   406
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   408
		/* can't make water of water! */
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   409
		if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || p2 == 1)) continue;
1632
10c391e108b7 (svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
Darkvater
parents: 1605
diff changeset
   410
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   411
		ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   412
		if (CmdFailed(ret)) return ret;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   413
		cost.AddCost(ret);
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3177
diff changeset
   414
3189
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3183
diff changeset
   415
		if (flags & DC_EXEC) {
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   416
			if (TileHeight(tile) == 0 && p2 == 1) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   417
				MakeWater(tile);
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   418
			} else if (p2 == 2) {
8368
dcee6c9440b5 (svn r11934) -Codechange: add persistent random data for river and canal tiles.
peter1138
parents: 8361
diff changeset
   419
				MakeRiver(tile, Random());
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   420
			} else {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10083
diff changeset
   421
				MakeCanal(tile, _current_company, Random());
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   422
			}
3189
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3183
diff changeset
   423
			MarkTileDirtyByTile(tile);
8443
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   424
			MarkCanalsAndRiversAroundDirty(tile);
3189
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3183
diff changeset
   425
		}
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3177
diff changeset
   426
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   427
		cost.AddCost(_price.clear_water);
1632
10c391e108b7 (svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
Darkvater
parents: 1605
diff changeset
   428
	} 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
   429
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   430
	if (cost.GetCost() == 0) {
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3177
diff changeset
   431
		return_cmd_error(STR_1007_ALREADY_BUILT);
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3177
diff changeset
   432
	} else {
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3177
diff changeset
   433
		return cost;
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3177
diff changeset
   434
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   437
static CommandCost ClearTile_Water(TileIndex tile, byte flags)
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   438
{
3425
5411e9c8b6c8 (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   439
	switch (GetWaterTileType(tile)) {
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
   440
		case WATER_TILE_CLEAR:
3425
5411e9c8b6c8 (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   441
			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
   442
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   443
			/* Make sure it's not an edge tile. */
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7948
diff changeset
   444
			if (!IsInsideMM(TileX(tile), 1, MapMaxX() - 1) ||
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7948
diff changeset
   445
					!IsInsideMM(TileY(tile), 1, MapMaxY() - 1)) {
3425
5411e9c8b6c8 (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   446
				return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP);
5411e9c8b6c8 (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   447
			}
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
   448
7509
23372ed624e8 (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: 7507
diff changeset
   449
			/* Make sure no vehicle is on the tile */
7758
17ad53748c7b (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: 7739
diff changeset
   450
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
7509
23372ed624e8 (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: 7507
diff changeset
   451
7270
7bbf428c2ead (svn r10593) -Fix [FS#1038]: one could not remove locks that were build in a (very) old version of OpenTTD.
rubidium
parents: 7266
diff changeset
   452
			if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE && !CheckTileOwnership(tile)) return CMD_ERROR;
3940
8965b9bfaabc (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
   453
8443
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   454
			if (flags & DC_EXEC) {
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   455
				DoClearSquare(tile);
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   456
				MarkCanalsAndRiversAroundDirty(tile);
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   457
			}
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   458
			return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
   460
		case WATER_TILE_COAST: {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   461
			Slope slope = GetTileSlope(tile, NULL);
3439
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   462
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   463
			/* Make sure no vehicle is on the tile */
7758
17ad53748c7b (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: 7739
diff changeset
   464
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
3439
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   465
8443
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   466
			if (flags & DC_EXEC) {
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   467
				DoClearSquare(tile);
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   468
				MarkCanalsAndRiversAroundDirty(tile);
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
   469
			}
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8386
diff changeset
   470
			if (IsSlopeWithOneCornerRaised(slope)) {
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   471
				return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water);
3439
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   472
			} else {
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   473
				return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_roughland);
3425
5411e9c8b6c8 (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   474
			}
3439
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   475
		}
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   476
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
   477
		case WATER_TILE_LOCK: {
3439
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   478
			static const TileIndexDiffC _shiplift_tomiddle_offs[] = {
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   479
				{ 0,  0}, {0,  0}, { 0, 0}, {0,  0}, // middle
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   480
				{-1,  0}, {0,  1}, { 1, 0}, {0, -1}, // lower
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   481
				{ 1,  0}, {0, -1}, {-1, 0}, {0,  1}, // upper
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   482
			};
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   483
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   484
			if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10083
diff changeset
   485
			if (_current_company == OWNER_WATER) return CMD_ERROR;
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   486
			/* move to the middle tile.. */
3439
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   487
			return RemoveShiplift(tile + ToTileIndexDiff(_shiplift_tomiddle_offs[GetSection(tile)]), flags);
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   488
		}
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   489
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
   490
		case WATER_TILE_DEPOT:
3425
5411e9c8b6c8 (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   491
			if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
5411e9c8b6c8 (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   492
			return RemoveShipDepot(tile, flags);
3439
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   493
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   494
		default:
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   495
			NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
8441
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   499
/**
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   500
 * return true if a tile is a water tile wrt. a certain direction.
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   501
 *
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   502
 * @param tile The tile of interest.
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   503
 * @param from The direction of interest.
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   504
 * @return true iff the tile is water in the view of 'from'.
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   505
 *
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   506
 */
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   507
static bool IsWateredTile(TileIndex tile, Direction from)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
{
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1209
diff changeset
   509
	switch (GetTileType(tile)) {
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3940
diff changeset
   510
		case MP_WATER:
9496
22b9581a7973 (svn r13476) -Fix: draw canal borders for locks and when directly next to a aquaduct entrace but under the aqueduct.
rubidium
parents: 9490
diff changeset
   511
			switch (GetWaterTileType(tile)) {
22b9581a7973 (svn r13476) -Fix: draw canal borders for locks and when directly next to a aquaduct entrace but under the aqueduct.
rubidium
parents: 9490
diff changeset
   512
				default: NOT_REACHED();
22b9581a7973 (svn r13476) -Fix: draw canal borders for locks and when directly next to a aquaduct entrace but under the aqueduct.
rubidium
parents: 9490
diff changeset
   513
				case WATER_TILE_DEPOT: case WATER_TILE_CLEAR: return true;
22b9581a7973 (svn r13476) -Fix: draw canal borders for locks and when directly next to a aquaduct entrace but under the aqueduct.
rubidium
parents: 9490
diff changeset
   514
				case WATER_TILE_LOCK: return DiagDirToAxis(GetLockDirection(tile)) == DiagDirToAxis(DirToDiagDir(from));
22b9581a7973 (svn r13476) -Fix: draw canal borders for locks and when directly next to a aquaduct entrace but under the aqueduct.
rubidium
parents: 9490
diff changeset
   515
22b9581a7973 (svn r13476) -Fix: draw canal borders for locks and when directly next to a aquaduct entrace but under the aqueduct.
rubidium
parents: 9490
diff changeset
   516
				case WATER_TILE_COAST:
22b9581a7973 (svn r13476) -Fix: draw canal borders for locks and when directly next to a aquaduct entrace but under the aqueduct.
rubidium
parents: 9490
diff changeset
   517
					switch (GetTileSlope(tile, NULL)) {
22b9581a7973 (svn r13476) -Fix: draw canal borders for locks and when directly next to a aquaduct entrace but under the aqueduct.
rubidium
parents: 9490
diff changeset
   518
						case SLOPE_W: return (from == DIR_SE) || (from == DIR_E) || (from == DIR_NE);
22b9581a7973 (svn r13476) -Fix: draw canal borders for locks and when directly next to a aquaduct entrace but under the aqueduct.
rubidium
parents: 9490
diff changeset
   519
						case SLOPE_S: return (from == DIR_NE) || (from == DIR_N) || (from == DIR_NW);
22b9581a7973 (svn r13476) -Fix: draw canal borders for locks and when directly next to a aquaduct entrace but under the aqueduct.
rubidium
parents: 9490
diff changeset
   520
						case SLOPE_E: return (from == DIR_NW) || (from == DIR_W) || (from == DIR_SW);
22b9581a7973 (svn r13476) -Fix: draw canal borders for locks and when directly next to a aquaduct entrace but under the aqueduct.
rubidium
parents: 9490
diff changeset
   521
						case SLOPE_N: return (from == DIR_SW) || (from == DIR_S) || (from == DIR_SE);
22b9581a7973 (svn r13476) -Fix: draw canal borders for locks and when directly next to a aquaduct entrace but under the aqueduct.
rubidium
parents: 9490
diff changeset
   522
						default: return false;
22b9581a7973 (svn r13476) -Fix: draw canal borders for locks and when directly next to a aquaduct entrace but under the aqueduct.
rubidium
parents: 9490
diff changeset
   523
					}
8441
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   524
			}
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3940
diff changeset
   525
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   526
		case MP_RAILWAY:
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   527
			if (GetRailGroundType(tile) == RAIL_GROUND_WATER) {
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   528
				assert(IsPlainRailTile(tile));
8441
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   529
				switch (GetTileSlope(tile, NULL)) {
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   530
					case SLOPE_W: return (from == DIR_SE) || (from == DIR_E) || (from == DIR_NE);
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   531
					case SLOPE_S: return (from == DIR_NE) || (from == DIR_N) || (from == DIR_NW);
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   532
					case SLOPE_E: return (from == DIR_NW) || (from == DIR_W) || (from == DIR_SW);
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   533
					case SLOPE_N: return (from == DIR_SW) || (from == DIR_S) || (from == DIR_SE);
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   534
					default: return false;
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   535
				}
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   536
			}
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   537
			return false;
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   538
9721
b6441d53c221 (svn r13845) -Fix (r13838): When adding a WaterClass to oilrig station tiles, also make use of it.
frosch
parents: 9718
diff changeset
   539
		case MP_STATION:
9722
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   540
			if (IsOilRig(tile)) {
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   541
				/* Do not draw waterborders inside of industries.
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   542
				 * Note: There is no easy way to detect the industry of an oilrig tile. */
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   543
				TileIndex src_tile = tile + TileOffsByDir(from);
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   544
				if ((IsTileType(src_tile, MP_STATION) && IsOilRig(src_tile)) ||
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   545
				    (IsTileType(src_tile, MP_INDUSTRY))) return true;
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   546
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   547
				return GetWaterClass(tile) != WATER_CLASS_INVALID;
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   548
			}
9721
b6441d53c221 (svn r13845) -Fix (r13838): When adding a WaterClass to oilrig station tiles, also make use of it.
frosch
parents: 9718
diff changeset
   549
			return (IsDock(tile) && GetTileSlope(tile, NULL) == SLOPE_FLAT) || IsBuoy(tile);
b6441d53c221 (svn r13845) -Fix (r13838): When adding a WaterClass to oilrig station tiles, also make use of it.
frosch
parents: 9718
diff changeset
   550
9722
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   551
		case MP_INDUSTRY: {
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   552
			/* Do not draw waterborders inside of industries.
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   553
			 * Note: There is no easy way to detect the industry of an oilrig tile. */
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   554
			TileIndex src_tile = tile + TileOffsByDir(from);
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   555
			if ((IsTileType(src_tile, MP_STATION) && IsOilRig(src_tile)) ||
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   556
			    (IsTileType(src_tile, MP_INDUSTRY) && GetIndustryIndex(src_tile) == GetIndustryIndex(tile))) return true;
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   557
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   558
			return IsIndustryTileOnWater(tile);
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   559
		}
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   560
9496
22b9581a7973 (svn r13476) -Fix: draw canal borders for locks and when directly next to a aquaduct entrace but under the aqueduct.
rubidium
parents: 9490
diff changeset
   561
		case MP_TUNNELBRIDGE: return GetTunnelBridgeTransportType(tile) == TRANSPORT_WATER && ReverseDiagDir(GetTunnelBridgeDirection(tile)) == DirToDiagDir(from);
9722
614d4514d37f (svn r13846) -Fix (r13838): Do not draw water borders inside of industries.
frosch
parents: 9721
diff changeset
   562
7507
36bb5300a128 (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7497
diff changeset
   563
		default:          return false;
1048
8611c5c02dcb (svn r1549) Clean up some functions:
tron
parents: 1041
diff changeset
   564
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   567
static void DrawWaterEdges(SpriteID base, TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
	uint wa;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   570
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   571
	/* determine the edges around with water. */
8441
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   572
	wa  = IsWateredTile(TILE_ADDXY(tile, -1,  0), DIR_SW) << 0;
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   573
	wa += IsWateredTile(TILE_ADDXY(tile,  0,  1), DIR_NW) << 1;
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   574
	wa += IsWateredTile(TILE_ADDXY(tile,  1,  0), DIR_NE) << 2;
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   575
	wa += IsWateredTile(TILE_ADDXY(tile,  0, -1), DIR_SE) << 3;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   576
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   577
	if (!(wa & 1)) DrawGroundSprite(base,     PAL_NONE);
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   578
	if (!(wa & 2)) DrawGroundSprite(base + 1, PAL_NONE);
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   579
	if (!(wa & 4)) DrawGroundSprite(base + 2, PAL_NONE);
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   580
	if (!(wa & 8)) DrawGroundSprite(base + 3, PAL_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   582
	/* right corner */
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   583
	switch (wa & 0x03) {
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   584
		case 0: DrawGroundSprite(base + 4, PAL_NONE); break;
8441
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   585
		case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1), DIR_W)) DrawGroundSprite(base + 8, PAL_NONE); break;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   586
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   588
	/* bottom corner */
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   589
	switch (wa & 0x06) {
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   590
		case 0: DrawGroundSprite(base + 5, PAL_NONE); break;
8441
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   591
		case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1), DIR_N)) DrawGroundSprite(base + 9, PAL_NONE); break;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   592
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   594
	/* left corner */
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   595
	switch (wa & 0x0C) {
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   596
		case  0: DrawGroundSprite(base + 6, PAL_NONE); break;
8441
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   597
		case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1), DIR_E)) DrawGroundSprite(base + 10, PAL_NONE); break;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   598
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   600
	/* upper corner */
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   601
	switch (wa & 0x09) {
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   602
		case 0: DrawGroundSprite(base + 7, PAL_NONE); break;
8441
6e5c4deb2b0b (svn r12011) -Fix [FS#1701]: Do not consider one-corner-raised-shores to be watered tiles from all sides.
frosch
parents: 8430
diff changeset
   603
		case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1), DIR_S)) DrawGroundSprite(base + 11, PAL_NONE); break;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   604
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   607
/** Draw a plain sea water tile with no edges */
8496
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   608
static void DrawSeaWater(TileIndex tile)
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   609
{
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   610
	DrawGroundSprite(SPR_FLAT_WATER_TILE, PAL_NONE);
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   611
}
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   612
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   613
/** draw a canal styled water tile with dikes around */
8496
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   614
static void DrawCanalWater(TileIndex tile)
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   615
{
8496
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   616
	DrawGroundSprite(SPR_FLAT_WATER_TILE, PAL_NONE);
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   617
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   618
	/* Test for custom graphics, else use the default */
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   619
	SpriteID dikes_base = GetCanalSprite(CF_DIKES, tile);
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   620
	if (dikes_base == 0) dikes_base = SPR_CANAL_DIKES_BASE;
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   621
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   622
	DrawWaterEdges(dikes_base, tile);
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   623
}
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   624
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6181
diff changeset
   625
struct LocksDrawTileStruct {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
	int8 delta_x, delta_y, delta_z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
	byte width, height, depth;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
	SpriteID image;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6181
diff changeset
   629
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
#include "table/water_land.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2261
diff changeset
   633
static void DrawWaterStuff(const TileInfo *ti, const WaterDrawTileStruct *wdts,
8496
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   634
	SpriteID palette, uint base, bool draw_ground
1399
61e7c68e9da6 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   635
)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
{
6583
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   637
	SpriteID image;
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   638
	SpriteID water_base = GetCanalSprite(CF_WATERSLOPE, ti->tile);
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   639
	SpriteID locks_base = GetCanalSprite(CF_LOCKS, ti->tile);
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   640
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   641
	/* If no custom graphics, use defaults */
7882
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7849
diff changeset
   642
	if (water_base == 0) water_base = SPR_CANALS_BASE;
6583
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   643
	if (locks_base == 0) {
7882
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7849
diff changeset
   644
		locks_base = SPR_SHIPLIFT_BASE;
6583
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   645
	} else {
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   646
		/* If using custom graphics, ignore the variation on height */
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   647
		base = 0;
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   648
	}
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   649
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   650
	image = wdts++->image;
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   651
	if (image < 4) image += water_base;
8496
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   652
	if (draw_ground) DrawGroundSprite(image, PAL_NONE);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   653
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8801
diff changeset
   654
	/* End now if buildings are invisible */
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8801
diff changeset
   655
	if (IsInvisibilitySet(TO_BUILDINGS)) return;
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8801
diff changeset
   656
1399
61e7c68e9da6 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   657
	for (; wdts->delta_x != 0x80; wdts++) {
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7270
diff changeset
   658
		AddSortableSpriteToDraw(wdts->image + base + ((wdts->image < 24) ? locks_base : 0), palette,
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   659
			ti->x + wdts->delta_x, ti->y + wdts->delta_y,
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   660
			wdts->width, wdts->height,
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7270
diff changeset
   661
			wdts->unk, ti->z + wdts->delta_z,
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7797
diff changeset
   662
			IsTransparencySet(TO_BUILDINGS));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
8496
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   666
static void DrawRiverWater(const TileInfo *ti)
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   667
{
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   668
	SpriteID image = SPR_FLAT_WATER_TILE;
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   669
	SpriteID edges_base = GetCanalSprite(CF_RIVER_EDGE, ti->tile);
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   670
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   671
	if (ti->tileh != SLOPE_FLAT) {
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   672
		image = GetCanalSprite(CF_RIVER_SLOPE, ti->tile);
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   673
		if (image == 0) {
8430
ecbc9ff4271d (svn r12000) -Fix (r11926): If no river NewGRF is loaded, use sloped water from locks.
frosch
parents: 8414
diff changeset
   674
			switch (ti->tileh) {
ecbc9ff4271d (svn r12000) -Fix (r11926): If no river NewGRF is loaded, use sloped water from locks.
frosch
parents: 8414
diff changeset
   675
				case SLOPE_NW: image = SPR_WATER_SLOPE_Y_DOWN; break;
ecbc9ff4271d (svn r12000) -Fix (r11926): If no river NewGRF is loaded, use sloped water from locks.
frosch
parents: 8414
diff changeset
   676
				case SLOPE_SW: image = SPR_WATER_SLOPE_X_UP;   break;
ecbc9ff4271d (svn r12000) -Fix (r11926): If no river NewGRF is loaded, use sloped water from locks.
frosch
parents: 8414
diff changeset
   677
				case SLOPE_SE: image = SPR_WATER_SLOPE_Y_UP;   break;
ecbc9ff4271d (svn r12000) -Fix (r11926): If no river NewGRF is loaded, use sloped water from locks.
frosch
parents: 8414
diff changeset
   678
				case SLOPE_NE: image = SPR_WATER_SLOPE_X_DOWN; break;
ecbc9ff4271d (svn r12000) -Fix (r11926): If no river NewGRF is loaded, use sloped water from locks.
frosch
parents: 8414
diff changeset
   679
				default:       image = SPR_FLAT_WATER_TILE;    break;
ecbc9ff4271d (svn r12000) -Fix (r11926): If no river NewGRF is loaded, use sloped water from locks.
frosch
parents: 8414
diff changeset
   680
			}
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   681
		} else {
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   682
			switch (ti->tileh) {
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   683
				default: NOT_REACHED();
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   684
				case SLOPE_SE:             edges_base += 12; break;
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   685
				case SLOPE_NE: image += 1; edges_base += 24; break;
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   686
				case SLOPE_SW: image += 2; edges_base += 36; break;
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   687
				case SLOPE_NW: image += 3; edges_base += 48; break;
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   688
			}
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   689
		}
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   690
	}
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   691
8496
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   692
	DrawGroundSprite(image, PAL_NONE);
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   693
8430
ecbc9ff4271d (svn r12000) -Fix (r11926): If no river NewGRF is loaded, use sloped water from locks.
frosch
parents: 8414
diff changeset
   694
	/* Draw river edges if available. */
ecbc9ff4271d (svn r12000) -Fix (r11926): If no river NewGRF is loaded, use sloped water from locks.
frosch
parents: 8414
diff changeset
   695
	if (edges_base > 48) DrawWaterEdges(edges_base, ti->tile);
8360
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   696
}
3021c928de6c (svn r11926) -Feature: Rivers. Graphics must be provided by NewGRF else rivers are drawn as canals. Rivers can currently only be placed with-in the scenario editor.
peter1138
parents: 8350
diff changeset
   697
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   698
void DrawShoreTile(Slope tileh)
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   699
{
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   700
	/* Converts the enum Slope into an offset based on SPR_SHORE_BASE.
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   701
	 * This allows to calculate the proper sprite to display for this Slope */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   702
	static const byte tileh_to_shoresprite[32] = {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   703
		0, 1, 2, 3, 4, 16, 6, 7, 8, 9, 17, 11, 12, 13, 14, 0,
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   704
		0, 0, 0, 0, 0,  0, 0, 0, 0, 0,  0,  5,  0, 10, 15, 0,
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   705
	};
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   706
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   707
	assert(!IsHalftileSlope(tileh)); // Halftile slopes need to get handled earlier.
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   708
	assert(tileh != SLOPE_FLAT);     // Shore is never flat
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   709
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   710
	assert((tileh != SLOPE_EW) && (tileh != SLOPE_NS)); // No suitable sprites for current flooding behaviour
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   711
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   712
	DrawGroundSprite(SPR_SHORE_BASE + tileh_to_shoresprite[tileh], PAL_NONE);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   713
}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   714
8496
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   715
void DrawWaterClassGround(const TileInfo *ti) {
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   716
	switch (GetWaterClass(ti->tile)) {
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   717
		case WATER_CLASS_SEA:   DrawSeaWater(ti->tile); break;
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   718
		case WATER_CLASS_CANAL: DrawCanalWater(ti->tile); break;
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   719
		case WATER_CLASS_RIVER: DrawRiverWater(ti); break;
9718
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   720
		default: NOT_REACHED();
8496
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   721
	}
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   722
}
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   723
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
static void DrawTile_Water(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
{
3402
812f9dc4baff (svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents: 3373
diff changeset
   726
	switch (GetWaterTileType(ti->tile)) {
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
   727
		case WATER_TILE_CLEAR:
8496
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   728
			DrawWaterClassGround(ti);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   729
			DrawBridgeMiddle(ti);
3402
812f9dc4baff (svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents: 3373
diff changeset
   730
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
8164
a448bc7576a5 (svn r11726) -Feature[newGRF]: Extend the Action 5, feature 0D usage. Patch by BigBB
belugas
parents: 8157
diff changeset
   732
		case WATER_TILE_COAST: {
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   733
			DrawShoreTile(ti->tileh);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   734
			DrawBridgeMiddle(ti);
8164
a448bc7576a5 (svn r11726) -Feature[newGRF]: Extend the Action 5, feature 0D usage. Patch by BigBB
belugas
parents: 8157
diff changeset
   735
		} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
   737
		case WATER_TILE_LOCK: {
3425
5411e9c8b6c8 (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   738
			const WaterDrawTileStruct *t = _shiplift_display_seq[GetSection(ti->tile)];
8496
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   739
			DrawWaterStuff(ti, t, 0, ti->z > t[3].delta_y ? 24 : 0, true);
3402
812f9dc4baff (svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents: 3373
diff changeset
   740
		} break;
812f9dc4baff (svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents: 3373
diff changeset
   741
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
   742
		case WATER_TILE_DEPOT:
8496
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8495
diff changeset
   743
			DrawWaterClassGround(ti);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10083
diff changeset
   744
			DrawWaterStuff(ti, _shipdepot_display_seq[GetSection(ti->tile)], COMPANY_SPRITE_COLOR(GetTileOwner(ti->tile)), 0, false);
3402
812f9dc4baff (svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents: 3373
diff changeset
   745
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
void DrawShipDepotSprite(int x, int y, int image)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
{
1399
61e7c68e9da6 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   751
	const WaterDrawTileStruct *wdts = _shipdepot_display_seq[image];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   753
	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
   754
1399
61e7c68e9da6 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   755
	for (; wdts->delta_x != 0x80; wdts++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
		Point pt = RemapCoords(wdts->delta_x, wdts->delta_y, wdts->delta_z);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10083
diff changeset
   757
		DrawSprite(wdts->image, COMPANY_SPRITE_COLOR(_local_company), x + pt.x, y + pt.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4171
diff changeset
   762
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
   763
{
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4171
diff changeset
   764
	uint z;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   765
	Slope tileh = GetTileSlope(tile, &z);
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4171
diff changeset
   766
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4171
diff changeset
   767
	return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
7335
141c6b86ec1f (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: 7333
diff changeset
   770
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
   771
{
7335
141c6b86ec1f (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: 7333
diff changeset
   772
	return FOUNDATION_NONE;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   773
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   774
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   775
static void GetAcceptedCargo_Water(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   780
static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
{
3402
812f9dc4baff (svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents: 3373
diff changeset
   782
	switch (GetWaterTileType(tile)) {
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
   783
		case WATER_TILE_CLEAR:
9517
8470042a618f (svn r13513) -Codechange: Give proper message when building a river fails.
belugas
parents: 9496
diff changeset
   784
			switch (GetWaterClass(tile)) {
8470042a618f (svn r13513) -Codechange: Give proper message when building a river fails.
belugas
parents: 9496
diff changeset
   785
				case WATER_CLASS_SEA:   td->str = STR_3804_WATER;     break;
8470042a618f (svn r13513) -Codechange: Give proper message when building a river fails.
belugas
parents: 9496
diff changeset
   786
				case WATER_CLASS_CANAL: td->str = STR_LANDINFO_CANAL; break;
8470042a618f (svn r13513) -Codechange: Give proper message when building a river fails.
belugas
parents: 9496
diff changeset
   787
				case WATER_CLASS_RIVER: td->str = STR_LANDINFO_RIVER; break;
8470042a618f (svn r13513) -Codechange: Give proper message when building a river fails.
belugas
parents: 9496
diff changeset
   788
				default: assert(0); break;
3402
812f9dc4baff (svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents: 3373
diff changeset
   789
			}
812f9dc4baff (svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents: 3373
diff changeset
   790
			break;
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
   791
		case WATER_TILE_COAST: td->str = STR_3805_COAST_OR_RIVERBANK; break;
9517
8470042a618f (svn r13513) -Codechange: Give proper message when building a river fails.
belugas
parents: 9496
diff changeset
   792
		case WATER_TILE_LOCK : td->str = STR_LANDINFO_LOCK;           break;
8470042a618f (svn r13513) -Codechange: Give proper message when building a river fails.
belugas
parents: 9496
diff changeset
   793
		case WATER_TILE_DEPOT: td->str = STR_3806_SHIP_DEPOT;         break;
3402
812f9dc4baff (svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents: 3373
diff changeset
   794
		default: assert(0); break;
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   795
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
9322
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9321
diff changeset
   797
	td->owner[0] = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   800
static void AnimateTile_Water(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   805
static void FloodVehicle(Vehicle *v);
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   806
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   807
/**
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   808
 * Flood a vehicle if we are allowed to flood it, i.e. when it is on the ground.
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   809
 * @param v    The vehicle to test for flooding.
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   810
 * @param data The z of level to flood.
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   811
 * @return NULL as we always want to remove everything.
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   812
 */
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   813
static Vehicle *FloodVehicleProc(Vehicle *v, void *data)
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   814
{
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   815
	byte z = *(byte*)data;
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   816
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   817
	if (v->type == VEH_DISASTER || (v->type == VEH_AIRCRAFT && v->subtype == AIR_SHADOW)) return NULL;
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   818
	if (v->z_pos > z || (v->vehstatus & VS_CRASHED) != 0) return NULL;
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   819
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   820
	FloodVehicle(v);
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   821
	return NULL;
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   822
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
5940
3bb99a7ad58f (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: 5905
diff changeset
   824
/**
3bb99a7ad58f (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: 5905
diff changeset
   825
 * Finds a vehicle to flood.
3bb99a7ad58f (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: 5905
diff changeset
   826
 * It does not find vehicles that are already crashed on bridges, i.e. flooded.
3bb99a7ad58f (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: 5905
diff changeset
   827
 * @param tile the tile where to find a vehicle to flood
3bb99a7ad58f (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: 5905
diff changeset
   828
 */
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   829
static void FloodVehicles(TileIndex tile)
5940
3bb99a7ad58f (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: 5905
diff changeset
   830
{
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   831
	byte z = 0;
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   832
6906
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   833
	if (IsTileType(tile, MP_STATION) && IsAirport(tile)) {
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   834
		const Station *st = GetStationByTile(tile);
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   835
		const AirportFTAClass *airport = st->Airport();
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   836
		z = 1 + airport->delta_z;
6906
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   837
		for (uint x = 0; x < airport->size_x; x++) {
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   838
			for (uint y = 0; y < airport->size_y; y++) {
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   839
				tile = TILE_ADDXY(st->airport_tile, x, y);
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   840
				FindVehicleOnPos(tile, &z, &FloodVehicleProc);
6906
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   841
			}
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   842
		}
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   843
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   844
		/* No vehicle could be flooded on this airport anymore */
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   845
		return;
6906
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   846
	}
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   847
8014
4a732fc3aade (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 7977
diff changeset
   848
	/* if non-uniform stations are disabled, flood some train in this train station (if there is any) */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9354
diff changeset
   849
	if (!_settings_game.station.nonuniform_stations && IsTileType(tile, MP_STATION) && GetStationType(tile) == STATION_RAIL) {
8014
4a732fc3aade (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 7977
diff changeset
   850
		const Station *st = GetStationByTile(tile);
4a732fc3aade (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 7977
diff changeset
   851
4a732fc3aade (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 7977
diff changeset
   852
		BEGIN_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile)
4a732fc3aade (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 7977
diff changeset
   853
			if (st->TileBelongsToRailStation(t)) {
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   854
				FindVehicleOnPos(tile, &z, &FloodVehicleProc);
8014
4a732fc3aade (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 7977
diff changeset
   855
			}
4a732fc3aade (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 7977
diff changeset
   856
		END_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile)
4a732fc3aade (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 7977
diff changeset
   857
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   858
		return;
8014
4a732fc3aade (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 7977
diff changeset
   859
	}
4a732fc3aade (svn r11574) -Fix: flood train stations when there are no trains on border tiles too (when non-uniform stations are OFF)
smatz
parents: 7977
diff changeset
   860
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   861
	if (!IsBridgeTile(tile)) {
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   862
		FindVehicleOnPos(tile, &z, &FloodVehicleProc);
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   863
		return;
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   864
	}
5940
3bb99a7ad58f (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: 5905
diff changeset
   865
3bb99a7ad58f (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: 5905
diff changeset
   866
	TileIndex end = GetOtherBridgeEnd(tile);
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   867
	z = GetBridgeHeight(tile);
5940
3bb99a7ad58f (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: 5905
diff changeset
   868
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   869
	FindVehicleOnPos(tile, &z, &FloodVehicleProc);
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
   870
	FindVehicleOnPos(end, &z, &FloodVehicleProc);
5940
3bb99a7ad58f (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: 5905
diff changeset
   871
}
3bb99a7ad58f (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: 5905
diff changeset
   872
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   873
static void FloodVehicle(Vehicle *v)
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   874
{
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   875
	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
   876
		uint16 pass = 0;
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   877
6906
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   878
		if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_AIRCRAFT) {
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   879
			if (v->type == VEH_AIRCRAFT) {
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   880
				/* Crashing aircraft are always at z_pos == 1, never on z_pos == 0,
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   881
				 * because that's always the shadow. Except for the heliport, because
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   882
				 * that station has a big z_offset for the aircraft. */
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   883
				if (!IsTileType(v->tile, MP_STATION) || !IsAirport(v->tile) || GetTileMaxZ(v->tile) != 0) return;
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   884
				const Station *st = GetStationByTile(v->tile);
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   885
				const AirportFTAClass *airport = st->Airport();
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   886
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   887
				if (v->z_pos != airport->delta_z + 1) return;
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   888
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   889
7497
40e457c0a8ac (svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents: 7494
diff changeset
   890
			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
   891
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6683
diff changeset
   892
			/* crash all wagons, and count passengers */
9321
61fd5b6e27ce (svn r13205) -Codechange: Remove unnecessary code-style-buggering-up macro.
peter1138
parents: 9297
diff changeset
   893
			for (Vehicle *u = v; u != NULL; u = u->Next()) {
61fd5b6e27ce (svn r13205) -Codechange: Remove unnecessary code-style-buggering-up macro.
peter1138
parents: 9297
diff changeset
   894
				if (IsCargoInClass(u->cargo_type, CC_PASSENGERS)) pass += u->cargo.Count();
61fd5b6e27ce (svn r13205) -Codechange: Remove unnecessary code-style-buggering-up macro.
peter1138
parents: 9297
diff changeset
   895
				u->vehstatus |= VS_CRASHED;
61fd5b6e27ce (svn r13205) -Codechange: Remove unnecessary code-style-buggering-up macro.
peter1138
parents: 9297
diff changeset
   896
				MarkSingleVehicleDirty(u);
61fd5b6e27ce (svn r13205) -Codechange: Remove unnecessary code-style-buggering-up macro.
peter1138
parents: 9297
diff changeset
   897
			}
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6683
diff changeset
   898
6906
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   899
			switch (v->type) {
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   900
				default: NOT_REACHED();
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   901
				case VEH_TRAIN:
9811
1942cbc26a51 (svn r13953) -Add [YAPP]: Free track reservations of crashed trains. (michi_cc)
rubidium
parents: 9722
diff changeset
   902
					if (IsFrontEngine(v)) {
1942cbc26a51 (svn r13953) -Add [YAPP]: Free track reservations of crashed trains. (michi_cc)
rubidium
parents: 9722
diff changeset
   903
						pass += 4; // driver
9948
1f1f5558ca20 (svn r14103) -Fix [YAPP]: flooded trains didn't free their reservation
smatz
parents: 9811
diff changeset
   904
						/* FreeTrainTrackReservation() calls GetVehicleTrackdir() that doesn't like crashed vehicles.
1f1f5558ca20 (svn r14103) -Fix [YAPP]: flooded trains didn't free their reservation
smatz
parents: 9811
diff changeset
   905
						 * In this case, v->direction matches v->u.rail.track, so we can do this (it wasn't crashed before) */
1f1f5558ca20 (svn r14103) -Fix [YAPP]: flooded trains didn't free their reservation
smatz
parents: 9811
diff changeset
   906
						v->vehstatus &= ~VS_CRASHED;
9811
1942cbc26a51 (svn r13953) -Add [YAPP]: Free track reservations of crashed trains. (michi_cc)
rubidium
parents: 9722
diff changeset
   907
						FreeTrainTrackReservation(v);
9948
1f1f5558ca20 (svn r14103) -Fix [YAPP]: flooded trains didn't free their reservation
smatz
parents: 9811
diff changeset
   908
						v->vehstatus |= VS_CRASHED;
9811
1942cbc26a51 (svn r13953) -Add [YAPP]: Free track reservations of crashed trains. (michi_cc)
rubidium
parents: 9722
diff changeset
   909
					}
6906
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   910
					v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9234
diff changeset
   911
					InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
6906
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   912
					break;
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   913
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   914
				case VEH_ROAD:
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   915
					if (IsRoadVehFront(v)) pass += 1; // driver
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   916
					v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9234
diff changeset
   917
					InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
6906
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   918
					break;
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   919
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   920
				case VEH_AIRCRAFT:
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   921
					pass += 2; // driver
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   922
					v->u.air.crashed_counter = 9000; // max 10000, disappear pretty fast
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9234
diff changeset
   923
					InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
6906
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   924
					break;
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6683
diff changeset
   925
			}
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   926
		} else {
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   927
			return;
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   928
		}
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   929
8350
8979cccdbed2 (svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz
parents: 8332
diff changeset
   930
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   931
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   932
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   933
		SetDParam(0, pass);
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   934
		AddNewsItem(STR_B006_FLOOD_VEHICLE_DESTROYED,
9234
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9224
diff changeset
   935
			NS_ACCIDENT_VEHICLE,
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   936
			v->index,
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   937
			0);
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   938
		CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   939
		SndPlayVehicleFx(SND_12_EXPLOSION, v);
714
503e96f37d46 (svn r1166) Fix: [ 1040119 ] Flooded wagons in depots don't keep constantly exploding any more
dominik
parents: 679
diff changeset
   940
	}
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   941
}
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   942
7731
0ddbab1c56bb (svn r11266) -Documentation: Add a few comments. Parts of BigBB's work on shores
belugas
parents: 7545
diff changeset
   943
/**
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   944
 * Returns the behaviour of a tile during flooding.
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   945
 *
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   946
 * @return Behaviour of the tile
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   947
 */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   948
static FloodingBehaviour GetFloodingBehaviour(TileIndex tile)
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   949
{
9718
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   950
	/* FLOOD_ACTIVE:  'single-corner-raised'-coast, sea, sea-shipdepots, sea-buoys, sea-docks (water part), rail with flooded halftile, sea-water-industries, sea-oilrigs
8459
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
   951
	 * FLOOD_DRYUP:   coast with more than one corner raised, coast with rail-track, coast with trees
9718
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   952
	 * FLOOD_PASSIVE: (not used)
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   953
	 * FLOOD_NONE:    canals, rivers, everything else
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   954
	 */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   955
	switch (GetTileType(tile)) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   956
		case MP_WATER:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   957
			if (IsCoast(tile)) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   958
				Slope tileh = GetTileSlope(tile, NULL);
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8386
diff changeset
   959
				return (IsSlopeWithOneCornerRaised(tileh) ? FLOOD_ACTIVE : FLOOD_DRYUP);
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   960
			} else {
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
   961
				return (GetWaterClass(tile) == WATER_CLASS_SEA) ? FLOOD_ACTIVE : FLOOD_NONE;
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   962
			}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   963
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   964
		case MP_RAILWAY:
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   965
			if (GetRailGroundType(tile) == RAIL_GROUND_WATER) {
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   966
				return (IsSlopeWithOneCornerRaised(GetTileSlope(tile, NULL)) ? FLOOD_ACTIVE : FLOOD_DRYUP);
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   967
			}
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   968
			return FLOOD_NONE;
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   969
8459
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
   970
		case MP_TREES:
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
   971
			return (GetTreeGround(tile) == TREE_GROUND_SHORE ? FLOOD_DRYUP : FLOOD_NONE);
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
   972
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   973
		case MP_STATION:
9718
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   974
			if (IsBuoy(tile) || (IsDock(tile) && GetTileSlope(tile, NULL) == SLOPE_FLAT) || IsOilRig(tile)) {
8497
b986e12ddabe (svn r12072) -Fix: Make docks at sea flood neighboured tiles.
frosch
parents: 8496
diff changeset
   975
				return (GetWaterClass(tile) == WATER_CLASS_SEA ? FLOOD_ACTIVE : FLOOD_NONE);
b986e12ddabe (svn r12072) -Fix: Make docks at sea flood neighboured tiles.
frosch
parents: 8496
diff changeset
   976
			}
9718
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   977
			return FLOOD_NONE;
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   978
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   979
		case MP_INDUSTRY:
9718
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9517
diff changeset
   980
			return ((IsIndustryTileOnWater(tile) && GetWaterClass(tile) == WATER_CLASS_SEA) ? FLOOD_ACTIVE : FLOOD_NONE);
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   981
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   982
		default:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   983
			return FLOOD_NONE;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   984
	}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   985
}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   986
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   987
/**
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   988
 * Floods a tile.
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   989
 */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   990
static void DoFloodTile(TileIndex target)
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   991
{
8684
80dc71578def (svn r12350) -Fix [FS#1836](r11947): do not try ti flood water tile (performance increase)
glx
parents: 8616
diff changeset
   992
	assert(!IsTileType(target, MP_WATER));
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   993
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   994
	bool flooded = false; // Will be set to true if something is changed.
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   995
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10083
diff changeset
   996
	_current_company = OWNER_WATER;
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   997
8459
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
   998
	Slope tileh = GetTileSlope(target, NULL);
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
   999
	if (tileh != SLOPE_FLAT) {
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1000
		/* make coast.. */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1001
		switch (GetTileType(target)) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1002
			case MP_RAILWAY: {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1003
				if (!IsPlainRailTile(target)) break;
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
  1004
				FloodVehicles(target);
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1005
				flooded = FloodHalftile(target);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1006
				break;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1007
			}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1008
8459
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
  1009
			case MP_TREES:
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
  1010
				if (!IsSlopeWithOneCornerRaised(tileh)) {
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
  1011
					SetTreeGroundDensity(target, TREE_GROUND_SHORE, 3);
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
  1012
					MarkTileDirtyByTile(target);
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
  1013
					flooded = true;
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
  1014
					break;
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
  1015
				}
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
  1016
			/* FALL THROUGH */
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1017
			case MP_CLEAR:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1018
				if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1019
					MakeShore(target);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1020
					MarkTileDirtyByTile(target);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1021
					flooded = true;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1022
				}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1023
				break;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1024
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1025
			default:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1026
				break;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1027
		}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1028
	} else {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1029
		/* Flood vehicles */
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9948
diff changeset
  1030
		FloodVehicles(target);
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1031
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1032
		/* flood flat tile */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1033
		if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1034
			MakeWater(target);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1035
			MarkTileDirtyByTile(target);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1036
			flooded = true;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1037
		}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1038
	}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1039
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1040
	if (flooded) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1041
		/* Mark surrounding canal tiles dirty too to avoid glitches */
8443
acae72eb6e52 (svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
frosch
parents: 8441
diff changeset
  1042
		MarkCanalsAndRiversAroundDirty(target);
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1043
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1044
		/* update signals if needed */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1045
		UpdateSignalsInBuffer();
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1046
	}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1047
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10083
diff changeset
  1048
	_current_company = OWNER_NONE;
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1049
}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1050
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1051
/**
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1052
 * Drys a tile up.
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1053
 */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1054
static void DoDryUp(TileIndex tile)
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1055
{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10083
diff changeset
  1056
	_current_company = OWNER_WATER;
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1057
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1058
	switch (GetTileType(tile)) {
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1059
		case MP_RAILWAY:
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1060
			assert(IsPlainRailTile(tile));
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1061
			assert(GetRailGroundType(tile) == RAIL_GROUND_WATER);
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1062
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1063
			RailGroundType new_ground;
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1064
			switch (GetTrackBits(tile)) {
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1065
				case TRACK_BIT_UPPER: new_ground = RAIL_GROUND_FENCE_HORIZ1; break;
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1066
				case TRACK_BIT_LOWER: new_ground = RAIL_GROUND_FENCE_HORIZ2; break;
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1067
				case TRACK_BIT_LEFT:  new_ground = RAIL_GROUND_FENCE_VERT1;  break;
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1068
				case TRACK_BIT_RIGHT: new_ground = RAIL_GROUND_FENCE_VERT2;  break;
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1069
				default: NOT_REACHED();
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1070
			}
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1071
			SetRailGroundType(tile, new_ground);
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1072
			MarkTileDirtyByTile(tile);
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1073
			break;
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1074
8459
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
  1075
		case MP_TREES:
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
  1076
			SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 3);
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
  1077
			MarkTileDirtyByTile(tile);
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
  1078
			break;
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8443
diff changeset
  1079
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1080
		case MP_WATER:
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1081
			assert(IsCoast(tile));
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1082
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1083
			if (CmdSucceeded(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1084
				MakeClear(tile, CLEAR_GRASS, 3);
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1085
				MarkTileDirtyByTile(tile);
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1086
			}
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1087
			break;
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1088
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1089
		default: NOT_REACHED();
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1090
	}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1091
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10083
diff changeset
  1092
	_current_company = OWNER_NONE;
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1093
}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1094
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1095
/**
7731
0ddbab1c56bb (svn r11266) -Documentation: Add a few comments. Parts of BigBB's work on shores
belugas
parents: 7545
diff changeset
  1096
 * Let a water tile floods its diagonal adjoining tiles
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7758
diff changeset
  1097
 * called from tunnelbridge_cmd, and by TileLoop_Industry() and TileLoop_Track()
7731
0ddbab1c56bb (svn r11266) -Documentation: Add a few comments. Parts of BigBB's work on shores
belugas
parents: 7545
diff changeset
  1098
 *
0ddbab1c56bb (svn r11266) -Documentation: Add a few comments. Parts of BigBB's work on shores
belugas
parents: 7545
diff changeset
  1099
 * @param tile the water/shore tile that floods
0ddbab1c56bb (svn r11266) -Documentation: Add a few comments. Parts of BigBB's work on shores
belugas
parents: 7545
diff changeset
  1100
 */
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
  1101
void TileLoop_Water(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
{
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1103
	switch (GetFloodingBehaviour(tile)) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1104
		case FLOOD_ACTIVE:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1105
			for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1106
				TileIndex dest = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(dir));
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1107
				if (dest == INVALID_TILE) continue;
8684
80dc71578def (svn r12350) -Fix [FS#1836](r11947): do not try ti flood water tile (performance increase)
glx
parents: 8616
diff changeset
  1108
				/* do not try to flood water tiles - increases performance a lot */
80dc71578def (svn r12350) -Fix [FS#1836](r11947): do not try ti flood water tile (performance increase)
glx
parents: 8616
diff changeset
  1109
				if (IsTileType(dest, MP_WATER)) continue;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
  1110
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1111
				uint z_dest;
8801
8c4b104b39ac (svn r12541) -Codechange: Declare Slope enum as bit set, and remove some (then) unneeded casts.
frosch
parents: 8787
diff changeset
  1112
				Slope slope_dest = GetFoundationSlope(dest, &z_dest) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP;
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1113
				if (z_dest > 0) continue;
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
  1114
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1115
				if (!HasBit(_flood_from_dirs[slope_dest], ReverseDir(dir))) continue;
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
  1116
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1117
				DoFloodTile(dest);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1118
			}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1119
			break;
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
  1120
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1121
		case FLOOD_DRYUP: {
8801
8c4b104b39ac (svn r12541) -Codechange: Declare Slope enum as bit set, and remove some (then) unneeded casts.
frosch
parents: 8787
diff changeset
  1122
			Slope slope_here = GetFoundationSlope(tile, NULL) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP;
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1123
			uint check_dirs = _flood_from_dirs[slope_here];
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1124
			uint dir;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1125
			FOR_EACH_SET_BIT(dir, check_dirs) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1126
				TileIndex dest = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir((Direction)dir));
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1127
				if (dest == INVALID_TILE) continue;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1128
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1129
				FloodingBehaviour dest_behaviour = GetFloodingBehaviour(dest);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1130
				if ((dest_behaviour == FLOOD_ACTIVE) || (dest_behaviour == FLOOD_PASSIVE)) return;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1131
			}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1132
			DoDryUp(tile);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1133
			break;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1134
		}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1135
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1136
		default: return;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
  1137
	}
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1138
}
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
  1139
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1140
void ConvertGroundTilesIntoWaterTiles()
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1141
{
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1142
	TileIndex tile;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1143
	uint z;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1144
	Slope slope;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1145
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1146
	for (tile = 0; tile < MapSize(); ++tile) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1147
		slope = GetTileSlope(tile, &z);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1148
		if (IsTileType(tile, MP_CLEAR) && z == 0) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1149
			/* Make both water for tiles at level 0
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1150
			 * and make shore, as that looks much better
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1151
			 * during the generation. */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1152
			switch (slope) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1153
				case SLOPE_FLAT:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1154
					MakeWater(tile);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1155
					break;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1156
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1157
				case SLOPE_N:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1158
				case SLOPE_E:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1159
				case SLOPE_S:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1160
				case SLOPE_W:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1161
					MakeShore(tile);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1162
					break;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1163
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1164
				default:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1165
					uint check_dirs = _flood_from_dirs[slope & ~SLOPE_STEEP];
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1166
					uint dir;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1167
					FOR_EACH_SET_BIT(dir, check_dirs) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1168
						TileIndex dest = TILE_ADD(tile, TileOffsByDir((Direction)dir));
8801
8c4b104b39ac (svn r12541) -Codechange: Declare Slope enum as bit set, and remove some (then) unneeded casts.
frosch
parents: 8787
diff changeset
  1169
						Slope slope_dest = GetTileSlope(dest, NULL) & ~SLOPE_STEEP;
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8386
diff changeset
  1170
						if (slope_dest == SLOPE_FLAT || IsSlopeWithOneCornerRaised(slope_dest)) {
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1171
							MakeShore(tile);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1172
							break;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1173
						}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1174
					}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1175
					break;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1176
			}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
  1177
		}
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
  1178
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8596
diff changeset
  1181
static TrackStatus GetTileTrackStatus_Water(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
{
3423
dab85d82708b (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
  1183
	static const byte coast_tracks[] = {0, 32, 4, 0, 16, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0};
4169
0d77cd42f6e6 (svn r5606) Replace some magic numbers by proper TrackBits enums and macros
tron
parents: 4101
diff changeset
  1184
0d77cd42f6e6 (svn r5606) Replace some magic numbers by proper TrackBits enums and macros
tron
parents: 4101
diff changeset
  1185
	TrackBits ts;
0d77cd42f6e6 (svn r5606) Replace some magic numbers by proper TrackBits enums and macros
tron
parents: 4101
diff changeset
  1186
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1187
	if (mode != TRANSPORT_WATER) return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
3423
dab85d82708b (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
  1189
	switch (GetWaterTileType(tile)) {
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
  1190
		case WATER_TILE_CLEAR: ts = (GetTileSlope(tile, NULL) == SLOPE_FLAT) ? TRACK_BIT_ALL : TRACK_BIT_NONE; break;
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
  1191
		case WATER_TILE_COAST: ts = (TrackBits)coast_tracks[GetTileSlope(tile, NULL) & 0xF]; break;
9224
93528d9cb96d (svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents: 9111
diff changeset
  1192
		case WATER_TILE_LOCK:  ts = DiagDirToDiagTrackBits(GetLockDirection(tile)); break;
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
  1193
		case WATER_TILE_DEPOT: ts = AxisToTrackBits(GetShipDepotAxis(tile)); break;
3423
dab85d82708b (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
  1194
		default: return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
	}
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1196
	if (TileX(tile) == 0) {
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
  1197
		/* NE border: remove tracks that connects NE tile edge */
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1198
		ts &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1199
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1200
	if (TileY(tile) == 0) {
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
  1201
		/* NW border: remove tracks that connects NW tile edge */
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1202
		ts &= ~(TRACK_BIT_Y | TRACK_BIT_LEFT | TRACK_BIT_UPPER);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1203
	}
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8596
diff changeset
  1204
	return CombineTrackStatus(TrackBitsToTrackdirBits(ts), TRACKDIR_BIT_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
  1207
static void ClickTile_Water(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
{
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
  1209
	if (GetWaterTileType(tile) == WATER_TILE_DEPOT) {
3423
dab85d82708b (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
  1210
		TileIndex tile2 = GetOtherShipDepotTile(tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
  1211
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1212
		ShowDepotWindow(tile < tile2 ? tile : tile2, VEH_SHIP);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10083
diff changeset
  1216
static void ChangeTileOwner_Water(TileIndex tile, Owner old_owner, Owner new_owner)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10083
diff changeset
  1218
	if (!IsTileOwner(tile, old_owner)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10083
diff changeset
  1220
	if (new_owner != INVALID_OWNER) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10083
diff changeset
  1221
		SetTileOwner(tile, new_owner);
8520
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1222
		return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
	}
8520
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1224
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1225
	/* Remove depot */
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1226
	if (IsShipDepot(tile)) DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1227
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1228
	/* Set owner of canals and locks ... and also canal under dock there was before.
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1229
	 * Check if the new owner after removing depot isn't OWNER_WATER. */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10083
diff changeset
  1230
	if (IsTileOwner(tile, old_owner)) SetTileOwner(tile, OWNER_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8116
diff changeset
  1233
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
  1234
{
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5954
diff changeset
  1235
	return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7443
diff changeset
  1238
static CommandCost TerraformTile_Water(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7443
diff changeset
  1239
{
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7443
diff changeset
  1240
	/* Canals can't be terraformed */
7739
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7731
diff changeset
  1241
	if (IsWaterTile(tile) && IsCanal(tile)) return_cmd_error(STR_MUST_DEMOLISH_CANAL_FIRST);
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7443
diff changeset
  1242
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7443
diff changeset
  1243
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7443
diff changeset
  1244
}
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7443
diff changeset
  1245
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1246
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1247
extern const TileTypeProcs _tile_type_water_procs = {
4344
7e123fec5b0b (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
  1248
	DrawTile_Water,           /* draw_tile_proc */
7e123fec5b0b (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
  1249
	GetSlopeZ_Water,          /* get_slope_z_proc */
7e123fec5b0b (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
  1250
	ClearTile_Water,          /* clear_tile_proc */
7e123fec5b0b (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
  1251
	GetAcceptedCargo_Water,   /* get_accepted_cargo_proc */
7e123fec5b0b (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
  1252
	GetTileDesc_Water,        /* get_tile_desc_proc */
7e123fec5b0b (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
  1253
	GetTileTrackStatus_Water, /* get_tile_track_status_proc */
7e123fec5b0b (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
  1254
	ClickTile_Water,          /* click_tile_proc */
7e123fec5b0b (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
  1255
	AnimateTile_Water,        /* animate_tile_proc */
7e123fec5b0b (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
  1256
	TileLoop_Water,           /* tile_loop_clear */
7e123fec5b0b (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
  1257
	ChangeTileOwner_Water,    /* change_tile_owner_clear */
7e123fec5b0b (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
  1258
	NULL,                     /* get_produced_cargo_proc */
7e123fec5b0b (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
  1259
	VehicleEnter_Water,       /* vehicle_enter_tile_proc */
7335
141c6b86ec1f (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: 7333
diff changeset
  1260
	GetFoundation_Water,      /* get_foundation_proc */
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7443
diff changeset
  1261
	TerraformTile_Water,      /* terraform_tile_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
};