src/water_cmd.cpp
author frosch
Tue, 22 Jan 2008 17:48:08 +0000
changeset 8380 174326093caa
parent 8368 dcee6c9440b5
child 8386 bed99ec71cb0
permissions -rw-r--r--
(svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
Tiles which only consist of shore do not flood anymore, instead they get removed if they are no longer connected to flooding water.
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
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
     3
/** @file water_cmd.cpp */
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"
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
    16
#include "news.h"
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1214
diff changeset
    17
#include "depot.h"
1752
d65cd19f7117 (svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents: 1632
diff changeset
    18
#include "vehicle_gui.h"
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2657
diff changeset
    19
#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
    20
#include "roadveh.h"
8108
b42a0e5c67ef (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents: 8105
diff changeset
    21
#include "water.h"
3111
750f37699a13 (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
    22
#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
    23
#include "industry_map.h"
5210
3415ef43c70a (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 4848
diff changeset
    24
#include "newgrf.h"
6583
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
    25
#include "newgrf_canal.h"
7389
08d6a6265ced (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7335
diff changeset
    26
#include "misc/autoptr.hpp"
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"
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8237
diff changeset
    34
#include "player_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"
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
    37
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    38
#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
    39
#include "table/strings.h"
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2186
diff changeset
    40
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    41
/**
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    42
 * 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
    43
 */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    44
enum FloodingBehaviour {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    45
	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
    46
	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
    47
	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
    48
	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
    49
};
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    50
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
 * 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
    53
 */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    54
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
    55
	(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
    56
	(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
    57
	(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
    58
	(1 << DIR_NE),                                                 // SLOPE_SW
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    59
	(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
    60
	0,                                                             // SLOPE_EW
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    61
	(1 << DIR_NW),                                                 // SLOPE_SE
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    62
	(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
    63
	(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
    64
	(1 << DIR_SE),                                                 // SLOPE_NW
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    65
	0,                                                             // SLOPE_NS
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    66
	(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
    67
	(1 << DIR_SW),                                                 // SLOPE_NE
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    68
	(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
    69
	(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
    70
};
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    71
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    72
/**
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    73
 * Slopes that contain flat water and not only shore.
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    74
 */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
    75
static const uint32 _active_water_slopes = (1 << SLOPE_FLAT) | (1 << SLOPE_W) | (1 << SLOPE_S) | (1 << SLOPE_E) | (1 << SLOPE_N);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
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
    77
/**
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
    78
 * Makes a tile canal or water depending on the surroundings.
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
    79
 * 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
    80
 * 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
    81
 * @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
    82
 * @param o the owner of the new tile.
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
    83
 */
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
    84
void MakeWaterOrCanalDependingOnSurroundings(TileIndex t, Owner o)
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
    85
{
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
    86
	assert(GetTileSlope(t, NULL) == SLOPE_FLAT);
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
    87
8022
3b4f24a14ace (svn r11582) -Fix: tiles were not marked dirty in some cases when removing a lock
smatz
parents: 8014
diff changeset
    88
	/* 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
    89
	MarkTileDirtyByTile(t);
3b4f24a14ace (svn r11582) -Fix: tiles were not marked dirty in some cases when removing a lock
smatz
parents: 8014
diff changeset
    90
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
    91
	/* Non-sealevel -> canal */
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
    92
	if (TileHeight(t) != 0) {
8368
dcee6c9440b5 (svn r11934) -Codechange: add persistent random data for river and canal tiles.
peter1138
parents: 8361
diff changeset
    93
		MakeCanal(t, o, Random());
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
    94
		return;
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
    95
	}
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
    96
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
    97
	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
    98
	bool has_canal = 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
    99
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
   100
	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
   101
		TileIndex neighbour = TileAddByDiagDir(t, 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
   102
		if (IsTileType(neighbour, MP_WATER)) {
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
   103
			has_water |= IsSea(neighbour) || IsCoast(neighbour) || (IsShipDepot(neighbour) && GetShipDepotWaterOwner(neighbour) == OWNER_WATER);
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
   104
			has_canal |= IsCanal(neighbour) || (IsShipDepot(neighbour) && GetShipDepotWaterOwner(neighbour) != OWNER_WATER);
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
		}
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
   106
	}
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
   107
	if (has_canal || !has_water) {
8368
dcee6c9440b5 (svn r11934) -Codechange: add persistent random data for river and canal tiles.
peter1138
parents: 8361
diff changeset
   108
		MakeCanal(t, o, Random());
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
	} else {
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
		MakeWater(t);
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
	}
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
}
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
   113
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
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1752
diff changeset
   115
/** 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
   116
 * @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
   117
 * @param flags type of operation
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6106
diff changeset
   118
 * @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
   119
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   121
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
   122
{
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
   123
	TileIndex tile2;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   124
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
   125
	CommandCost ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6106
diff changeset
   127
	Axis axis = Extract<Axis, 0>(p1);
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6106
diff changeset
   128
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6106
diff changeset
   129
	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
   130
7739
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7731
diff changeset
   131
	if (!IsWaterTile(tile) || !IsWaterTile(tile2))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
		return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   134
	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
   135
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
   136
	Owner o1 = GetTileOwner(tile);
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
   137
	Owner o2 = GetTileOwner(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
   138
	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
   139
	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
   140
	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
   141
	if (CmdFailed(ret)) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   142
7389
08d6a6265ced (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7335
diff changeset
   143
	Depot *depot = new Depot(tile);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1752
diff changeset
   144
	if (depot == NULL) return CMD_ERROR;
7389
08d6a6265ced (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7335
diff changeset
   145
	AutoPtrT<Depot> d_auto_delete = depot;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
	if (flags & DC_EXEC) {
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1214
diff changeset
   148
		depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
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
   150
		MakeShipDepot(tile,  _current_player, DEPOT_NORTH, axis, o1);
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
   151
		MakeShipDepot(tile2, _current_player, DEPOT_SOUTH, axis, o2);
3372
f6afa98d5219 (svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents: 3338
diff changeset
   152
		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
   153
		MarkTileDirtyByTile(tile2);
7389
08d6a6265ced (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7335
diff changeset
   154
		d_auto_delete.Detach();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
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
   157
	return CommandCost(EXPENSES_CONSTRUCTION, _price.build_ship_depot);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
8105
49739cef9a00 (svn r11666) -Fix (r11504): when removing buoys, return to water or canal depending on their owner
glx
parents: 8044
diff changeset
   160
void MakeWaterOrCanalDependingOnOwner(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
   161
{
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
   162
	if (o == OWNER_WATER) {
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
   163
		MakeWater(tile);
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
   164
	} else {
8368
dcee6c9440b5 (svn r11934) -Codechange: add persistent random data for river and canal tiles.
peter1138
parents: 8361
diff changeset
   165
		MakeCanal(tile, o, Random());
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
   166
	}
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
   167
}
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
   168
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   169
static CommandCost RemoveShipDepot(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
{
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   171
	TileIndex tile2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
3373
2838aadd3a28 (svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents: 3372
diff changeset
   173
	if (!IsShipDepot(tile)) return CMD_ERROR;
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   174
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
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
   175
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
3373
2838aadd3a28 (svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents: 3372
diff changeset
   177
	tile2 = GetOtherShipDepotTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
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
   179
	if (!EnsureNoVehicleOnGround(tile2)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
	if (flags & DC_EXEC) {
3373
2838aadd3a28 (svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
celestar
parents: 3372
diff changeset
   182
		/* 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
   183
		delete GetDepotByTile(tile2 < tile ? tile2 : tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
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
   185
		MakeWaterOrCanalDependingOnOwner(tile,  GetShipDepotWaterOwner(tile));
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
   186
		MakeWaterOrCanalDependingOnOwner(tile2, GetShipDepotWaterOwner(tile2));
3111
750f37699a13 (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
   187
		MarkTileDirtyByTile(tile);
750f37699a13 (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3017
diff changeset
   188
		MarkTileDirtyByTile(tile2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
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
   191
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_ship_depot);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
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
   194
/** build a shiplift */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   195
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
   196
{
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   197
	CommandCost ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
	int delta;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
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
   200
	/* 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
   201
	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
   202
	if (CmdFailed(ret)) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   203
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4434
diff changeset
   204
	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
   205
	/* lower tile */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3439
diff changeset
   206
	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
   207
	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
   208
	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
   209
		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
   210
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
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
   212
	/* upper tile */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3439
diff changeset
   213
	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
   214
	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
   215
	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
   216
		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
   217
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   219
	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
   220
	    (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
   221
	    (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
   222
		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
   223
	}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   224
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
	if (flags & DC_EXEC) {
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
   226
		MakeLock(tile, _current_player, dir);
3372
f6afa98d5219 (svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
celestar
parents: 3338
diff changeset
   227
		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
   228
		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
   229
		MarkTileDirtyByTile(tile + delta);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
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
   232
	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
   233
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   235
static CommandCost RemoveShiplift(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
{
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4434
diff changeset
   237
	TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
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
   239
	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
   240
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
   241
	/* 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
   242
	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
   243
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
		DoClearSquare(tile);
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
   247
		MakeWaterOrCanalDependingOnSurroundings(tile + delta, _current_player);
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
   248
		MakeWaterOrCanalDependingOnSurroundings(tile - delta, _current_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   250
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
   251
	return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
7545
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7509
diff changeset
   254
/**
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7509
diff changeset
   255
 * Marks the tiles around a tile as dirty.
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7509
diff changeset
   256
 *
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7509
diff changeset
   257
 * This functions marks the tiles around a given tile as dirty for repaint.
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7509
diff changeset
   258
 *
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7509
diff changeset
   259
 * @param tile The center of the tile where all other tiles are marked as dirty
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7509
diff changeset
   260
 * @ingroup dirty
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7509
diff changeset
   261
 * @see TerraformAddDirtyTileAround
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7509
diff changeset
   262
 */
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   263
static void MarkTilesAroundDirty(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
	MarkTileDirtyByTile(TILE_ADDXY(tile, 0, 1));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
	MarkTileDirtyByTile(TILE_ADDXY(tile, 0, -1));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
	MarkTileDirtyByTile(TILE_ADDXY(tile, 1, 0));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
	MarkTileDirtyByTile(TILE_ADDXY(tile, -1, 0));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
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
   271
/** 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
   272
 * @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
   273
 * @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
   274
 * @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
   275
 * @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
   276
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   277
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
   278
{
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3111
diff changeset
   279
	DiagDirection dir;
889
64d2f7d5f02b (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 863
diff changeset
   280
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3111
diff changeset
   281
	switch (GetTileSlope(tile, NULL)) {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   282
		case SLOPE_SW: dir = DIAGDIR_SW; break;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   283
		case SLOPE_SE: dir = DIAGDIR_SE; break;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   284
		case SLOPE_NW: dir = DIAGDIR_NW; break;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   285
		case SLOPE_NE: dir = DIAGDIR_NE; break;
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3111
diff changeset
   286
		default: return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1784
diff changeset
   287
	}
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3111
diff changeset
   288
	return DoBuildShiplift(tile, dir, flags);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
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
   291
/** 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
   292
 * @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
   293
 * @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
   294
 * @param p1 start tile of stretch-dragging
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
   295
 * @param p2 ctrl pressed - toggles ocean / canals at sealevel (ocean only allowed in the 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
   296
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   297
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
   298
{
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
   299
	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
   300
	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
   301
	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
   302
	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
   303
	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
   304
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
   305
	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
   306
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
   307
	/* 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
   308
	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
   309
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
   310
	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
   311
	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
   312
	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
   313
	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
   314
6106
2898cd9417fd (svn r8841) -Fix
tron
parents: 5991
diff changeset
   315
	if (x < sx) Swap(x, sx);
2898cd9417fd (svn r8841) -Fix
tron
parents: 5991
diff changeset
   316
	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
   317
	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
   318
	size_y = (y - sy) + 1;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   319
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
   320
	/* 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
   321
	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
   322
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   323
	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
   324
		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
   325
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
   326
		Slope slope = GetTileSlope(tile, NULL);
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
   327
		if (slope != SLOPE_FLAT && (p2 != 2 || (slope != SLOPE_NW && slope != SLOPE_NE && slope != SLOPE_SW && slope != SLOPE_SE))) {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   328
			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
   329
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
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
   331
		/* 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
   332
		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
   333
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   334
		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
   335
		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
   336
		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
   337
3189
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3183
diff changeset
   338
		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
   339
			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
   340
				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
   341
			} else if (p2 == 2) {
8368
dcee6c9440b5 (svn r11934) -Codechange: add persistent random data for river and canal tiles.
peter1138
parents: 8361
diff changeset
   342
				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
   343
			} else {
8368
dcee6c9440b5 (svn r11934) -Codechange: add persistent random data for river and canal tiles.
peter1138
parents: 8361
diff changeset
   344
				MakeCanal(tile, _current_player, 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
   345
			}
3189
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3183
diff changeset
   346
			MarkTileDirtyByTile(tile);
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3183
diff changeset
   347
			MarkTilesAroundDirty(tile);
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3183
diff changeset
   348
		}
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
   349
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   350
		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
   351
	} 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
   352
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   353
	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
   354
		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
   355
	} 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
   356
		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
   357
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6906
diff changeset
   360
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
   361
{
3425
5411e9c8b6c8 (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   362
	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
   363
		case WATER_TILE_CLEAR:
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
   364
		case WATER_TILE_RIVER:
3425
5411e9c8b6c8 (svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
celestar
parents: 3423
diff changeset
   365
			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
   366
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
   367
			/* 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
   368
			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
   369
					!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
   370
				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
   371
			}
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
   372
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
   373
			/* 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
   374
			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
   375
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
   376
			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
   377
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
   378
			if (flags & DC_EXEC) DoClearSquare(tile);
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
   379
			return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
   381
		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
   382
			Slope slope = GetTileSlope(tile, NULL);
3439
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   383
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
   384
			/* 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
   385
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
3439
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   386
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   387
			if (flags & DC_EXEC) DoClearSquare(tile);
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   388
			if (slope == SLOPE_N || slope == SLOPE_E || slope == SLOPE_S || slope == SLOPE_W) {
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
   389
				return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water);
3439
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   390
			} 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
   391
				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
   392
			}
3439
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   393
		}
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   394
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
   395
		case WATER_TILE_LOCK: {
3439
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   396
			static const TileIndexDiffC _shiplift_tomiddle_offs[] = {
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   397
				{ 0,  0}, {0,  0}, { 0, 0}, {0,  0}, // middle
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   398
				{-1,  0}, {0,  1}, { 1, 0}, {0, -1}, // lower
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   399
				{ 1,  0}, {0, -1}, {-1, 0}, {0,  1}, // upper
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   400
			};
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   401
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   402
			if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   403
			if (_current_player == 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
   404
			/* move to the middle tile.. */
3439
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   405
			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
   406
		}
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   407
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
   408
		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
   409
			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
   410
			return RemoveShipDepot(tile, flags);
3439
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   411
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   412
		default:
60f16e7f2573 (svn r4269) We don't use GNU indentation style
tron
parents: 3436
diff changeset
   413
			NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
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
   417
/** return true if a tile is a water tile. */
1048
8611c5c02dcb (svn r1549) Clean up some functions:
tron
parents: 1041
diff changeset
   418
static bool IsWateredTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
{
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1209
diff changeset
   420
	switch (GetTileType(tile)) {
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3940
diff changeset
   421
		case MP_WATER:
4087
d6a79200cb20 (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   422
			if (!IsCoast(tile)) return true;
d6a79200cb20 (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   423
d6a79200cb20 (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   424
			switch (GetTileSlope(tile, NULL)) {
d6a79200cb20 (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   425
				case SLOPE_W:
d6a79200cb20 (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   426
				case SLOPE_S:
d6a79200cb20 (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   427
				case SLOPE_E:
d6a79200cb20 (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   428
				case SLOPE_N:
d6a79200cb20 (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   429
					return true;
d6a79200cb20 (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   430
d6a79200cb20 (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   431
				default:
d6a79200cb20 (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   432
					return false;
d6a79200cb20 (svn r5403) - Feature: Allow building canals at sea-level, using ctrl to toggle canal or plain water tile. This allows building of non-raisable sea-level water ways (useful in multiplayer) and dikes for low-level areas.
peter1138
parents: 4077
diff changeset
   433
			}
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3940
diff changeset
   434
8274
cc1350409528 (svn r11838) -Fix (r11320): draw correctly canal next to half flooded rail tile
smatz
parents: 8270
diff changeset
   435
		case MP_RAILWAY:  return GetRailGroundType(tile) == RAIL_GROUND_WATER;
7507
36bb5300a128 (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7497
diff changeset
   436
		case MP_STATION:  return IsOilRig(tile) || IsDock(tile) || IsBuoy(tile);
36bb5300a128 (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7497
diff changeset
   437
		case MP_INDUSTRY: return (GetIndustrySpec(GetIndustryType(tile))->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0;
36bb5300a128 (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7497
diff changeset
   438
		default:          return false;
1048
8611c5c02dcb (svn r1549) Clean up some functions:
tron
parents: 1041
diff changeset
   439
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
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
   442
static void DrawWaterEdges(SpriteID base, TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
	uint wa;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   445
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
   446
	/* determine the edges around with water. */
7507
36bb5300a128 (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7497
diff changeset
   447
	wa  = IsWateredTile(TILE_ADDXY(tile, -1,  0)) << 0;
36bb5300a128 (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7497
diff changeset
   448
	wa += IsWateredTile(TILE_ADDXY(tile,  0,  1)) << 1;
36bb5300a128 (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7497
diff changeset
   449
	wa += IsWateredTile(TILE_ADDXY(tile,  1,  0)) << 2;
36bb5300a128 (svn r11022) -Fix: the canal border determination did not take oil rigs into consideration.
rubidium
parents: 7497
diff changeset
   450
	wa += IsWateredTile(TILE_ADDXY(tile,  0, -1)) << 3;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   451
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
   452
	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
   453
	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
   454
	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
   455
	if (!(wa & 8)) DrawGroundSprite(base + 3, PAL_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
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
   457
	/* right corner */
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   458
	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
   459
		case 0: DrawGroundSprite(base + 4, PAL_NONE); 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
   460
		case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(base + 8, PAL_NONE); break;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   461
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
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
	/* bottom corner */
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   464
	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
   465
		case 0: DrawGroundSprite(base + 5, PAL_NONE); 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
   466
		case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(base + 9, PAL_NONE); break;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   467
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
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
   469
	/* left corner */
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   470
	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
   471
		case  0: DrawGroundSprite(base + 6, PAL_NONE); 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
   472
		case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(base + 10, PAL_NONE); break;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   473
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
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
   475
	/* upper corner */
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   476
	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
   477
		case 0: DrawGroundSprite(base + 7, PAL_NONE); 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
   478
		case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(base + 11, PAL_NONE); break;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   479
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
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
   482
/** draw a canal styled water tile with dikes around */
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
   483
void DrawCanalWater(TileIndex 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
   484
{
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
   485
	/* 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
   486
	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
   487
	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
   488
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
   489
	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
   490
}
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
   491
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6181
diff changeset
   492
struct LocksDrawTileStruct {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
	int8 delta_x, delta_y, delta_z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
	byte width, height, depth;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
	SpriteID image;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6181
diff changeset
   496
};
0
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
#include "table/water_land.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
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
   500
static void DrawWaterStuff(const TileInfo *ti, const WaterDrawTileStruct *wdts,
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   501
	SpriteID palette, uint base
1399
61e7c68e9da6 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   502
)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
{
6583
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   504
	SpriteID image;
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   505
	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
   506
	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
   507
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   508
	/* 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
   509
	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
   510
	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
   511
		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
   512
	} else {
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   513
		/* 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
   514
		base = 0;
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   515
	}
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   516
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   517
	image = wdts++->image;
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   518
	if (image < 4) image += water_base;
71d62b85d3ad (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 6491
diff changeset
   519
	DrawGroundSprite(image, PAL_NONE);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   520
1399
61e7c68e9da6 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   521
	for (; wdts->delta_x != 0x80; wdts++) {
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7270
diff changeset
   522
		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
   523
			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
   524
			wdts->width, wdts->height,
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7270
diff changeset
   525
			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
   526
			IsTransparencySet(TO_BUILDINGS));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
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
   530
static void DrawRiverWater(const TileInfo *ti)
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
   531
{
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
   532
	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
   533
	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
   534
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
   535
	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
   536
		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
   537
		if (image == 0) {
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
   538
			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
   539
		} 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
   540
			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
   541
				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
   542
				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
   543
				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
   544
				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
   545
				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
   546
			}
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
   547
		}
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
   548
	}
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
   549
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
   550
	DrawGroundSprite(image, 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
   551
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
   552
	/* Draw canal dikes if there are no river edges to draw. */
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
   553
	if (edges_base <= 48) edges_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
   554
	DrawWaterEdges(edges_base, 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
   555
}
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
   556
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   557
void DrawShoreTile(Slope tileh)
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   558
{
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   559
	/* 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
   560
	 * 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
   561
	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
   562
		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
   563
		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
   564
	};
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   565
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   566
	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
   567
	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
   568
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   569
	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
   570
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   571
	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
   572
}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   573
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
static void DrawTile_Water(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
{
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
   576
	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
   577
		case WATER_TILE_CLEAR:
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   578
			DrawGroundSprite(SPR_FLAT_WATER_TILE, PAL_NONE);
7739
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7731
diff changeset
   579
			if (IsCanal(ti->tile)) DrawCanalWater(ti->tile);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5210
diff changeset
   580
			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
   581
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
8164
a448bc7576a5 (svn r11726) -Feature[newGRF]: Extend the Action 5, feature 0D usage. Patch by BigBB
belugas
parents: 8157
diff changeset
   583
		case WATER_TILE_COAST: {
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   584
			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
   585
			DrawBridgeMiddle(ti);
8164
a448bc7576a5 (svn r11726) -Feature[newGRF]: Extend the Action 5, feature 0D usage. Patch by BigBB
belugas
parents: 8157
diff changeset
   586
		} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
   588
		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
   589
			const WaterDrawTileStruct *t = _shiplift_display_seq[GetSection(ti->tile)];
3402
812f9dc4baff (svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents: 3373
diff changeset
   590
			DrawWaterStuff(ti, t, 0, ti->z > t[3].delta_y ? 24 : 0);
812f9dc4baff (svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents: 3373
diff changeset
   591
		} 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
   592
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
   593
		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
   594
			DrawWaterStuff(ti, _shipdepot_display_seq[GetSection(ti->tile)], PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), 0);
3402
812f9dc4baff (svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents: 3373
diff changeset
   595
			break;
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
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
   597
		case WATER_TILE_RIVER:
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
   598
			DrawRiverWater(ti);
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
   599
			DrawBridgeMiddle(ti);
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
   600
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
void DrawShipDepotSprite(int x, int y, int image)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
{
1399
61e7c68e9da6 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   606
	const WaterDrawTileStruct *wdts = _shipdepot_display_seq[image];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   608
	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
   609
1399
61e7c68e9da6 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
   610
	for (; wdts->delta_x != 0x80; wdts++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
		Point pt = RemapCoords(wdts->delta_x, wdts->delta_y, wdts->delta_z);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   612
		DrawSprite(wdts->image, PLAYER_SPRITE_COLOR(_local_player), x + pt.x, y + pt.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4171
diff changeset
   617
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
   618
{
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4171
diff changeset
   619
	uint z;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   620
	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
   621
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4171
diff changeset
   622
	return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
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
   625
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
   626
{
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
   627
	return FOUNDATION_NONE;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   628
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   629
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   630
static void GetAcceptedCargo_Water(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   635
static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
{
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
   637
	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
   638
		case WATER_TILE_CLEAR:
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
   639
		case WATER_TILE_RIVER:
7739
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7731
diff changeset
   640
			if (!IsCanal(tile)) {
3402
812f9dc4baff (svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents: 3373
diff changeset
   641
				td->str = STR_3804_WATER;
812f9dc4baff (svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents: 3373
diff changeset
   642
			} else {
812f9dc4baff (svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents: 3373
diff changeset
   643
				td->str = STR_LANDINFO_CANAL;
812f9dc4baff (svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
celestar
parents: 3373
diff changeset
   644
			}
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
   645
			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
   646
		case WATER_TILE_COAST: td->str = STR_3805_COAST_OR_RIVERBANK; break;
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
   647
		case WATER_TILE_LOCK : td->str = STR_LANDINFO_LOCK; break;
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
   648
		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
   649
		default: assert(0); break;
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   650
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   652
	td->owner = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   655
static void AnimateTile_Water(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7758
diff changeset
   660
/**
8044
607a40999520 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8029
diff changeset
   661
 * Marks tile dirty if it is a canal tile.
607a40999520 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8029
diff changeset
   662
 * Called to avoid glitches when flooding tiles next to canal tile.
607a40999520 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8029
diff changeset
   663
 *
607a40999520 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8029
diff changeset
   664
 * @param tile tile to check
607a40999520 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8029
diff changeset
   665
 */
8331
5514b3a1d52c (svn r11897) -Fix: Replace an uint with TileIndex and a small coding style fix.
frosch
parents: 8317
diff changeset
   666
static inline void MarkTileDirtyIfCanal(TileIndex tile)
5514b3a1d52c (svn r11897) -Fix: Replace an uint with TileIndex and a small coding style fix.
frosch
parents: 8317
diff changeset
   667
{
8044
607a40999520 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8029
diff changeset
   668
	if (IsTileType(tile, MP_WATER) && IsCanal(tile)) MarkTileDirtyByTile(tile);
607a40999520 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8029
diff changeset
   669
}
607a40999520 (svn r11604) -Fix: canal tiles were not marked dirty when surrounding tile got flooded, causing glitches
smatz
parents: 8029
diff changeset
   670
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
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
   672
/**
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
   673
 * 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
   674
 * 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
   675
 * @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
   676
 * @return a vehicle too flood or NULL when there is no vehicle too 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
   677
 */
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
   678
static Vehicle *FindFloodableVehicleOnTile(TileIndex tile)
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
   679
{
6906
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   680
	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
   681
		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
   682
		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
   683
		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
   684
			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
   685
				tile = TILE_ADDXY(st->airport_tile, x, y);
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   686
				Vehicle *v = FindVehicleOnTileZ(tile, 1 + airport->delta_z);
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   687
				if (v != NULL && (v->vehstatus & VS_CRASHED) == 0) return v;
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   688
			}
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   689
		}
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   690
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   691
		/* No vehicle could be flooded on this airport anymore */
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   692
		return NULL;
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   693
	}
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   694
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
   695
	/* if non-uniform stations are disabled, flood some train in this train station (if there is any) */
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
   696
	if (!_patches.nonuniform_stations && IsTileType(tile, MP_STATION) && GetStationType(tile) == STATION_RAIL) {
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
   697
		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
   698
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
   699
		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
   700
			if (st->TileBelongsToRailStation(t)) {
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
   701
				Vehicle *v = FindVehicleOnTileZ(t, 0);
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
   702
				if (v != NULL && (v->vehstatus & VS_CRASHED) == 0) return v;
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
   703
			}
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
   704
		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
   705
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
   706
		return NULL;
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
   707
	}
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
   708
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
   709
	if (!IsBridgeTile(tile)) return FindVehicleOnTileZ(tile, 0);
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
   710
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
   711
	TileIndex end = GetOtherBridgeEnd(tile);
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
   712
	byte z = GetBridgeHeight(tile);
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
   713
	Vehicle *v;
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
   714
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
   715
	/* check the start tile first since as this is closest to the water */
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
   716
	v = FindVehicleOnTileZ(tile, z);
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
   717
	if (v != NULL && (v->vehstatus & VS_CRASHED) == 0) return v;
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
   718
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
   719
	/* check a vehicle in between both bridge heads */
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
   720
	v = FindVehicleBetween(tile, end, z, true);
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
   721
	if (v != NULL) return v;
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
   722
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
   723
	/* check the end tile last to give fleeing vehicles a chance to escape */
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
   724
	v = FindVehicleOnTileZ(end, z);
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
   725
	return (v != NULL && (v->vehstatus & VS_CRASHED) == 0) ? v : NULL;
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
   726
}
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
   727
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   728
static void FloodVehicle(Vehicle *v)
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   729
{
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   730
	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
   731
		uint16 pass = 0;
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   732
6906
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   733
		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
   734
			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
   735
				/* 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
   736
				 * 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
   737
				 * 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
   738
				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
   739
				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
   740
				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
   741
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   742
				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
   743
			}
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4169
diff changeset
   744
			Vehicle *u;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   745
7497
40e457c0a8ac (svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents: 7494
diff changeset
   746
			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
   747
			u = v;
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   748
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6683
diff changeset
   749
			/* crash all wagons, and count passengers */
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   750
			BEGIN_ENUM_WAGONS(v)
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6950
diff changeset
   751
				if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.Count();
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   752
				v->vehstatus |= VS_CRASHED;
8317
539038de35cb (svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents: 8306
diff changeset
   753
				MarkSingleVehicleDirty(v);
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   754
			END_ENUM_WAGONS(v)
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   755
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   756
			v = u;
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6683
diff changeset
   757
6906
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   758
			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
   759
				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
   760
				case VEH_TRAIN:
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   761
					if (IsFrontEngine(v)) pass += 4; // driver
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   762
					v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   763
					break;
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   764
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   765
				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
   766
					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
   767
					v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   768
					break;
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   769
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   770
				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
   771
					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
   772
					v->u.air.crashed_counter = 9000; // max 10000, disappear pretty fast
80503931fe10 (svn r10155) -Fix [FS#601]: Airports didn't flood when there are aircraft on the airport.
rubidium
parents: 6857
diff changeset
   773
					break;
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6683
diff changeset
   774
			}
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6683
diff changeset
   775
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 541
diff changeset
   776
			RebuildVehicleLists();
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   777
		} else {
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   778
			return;
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   779
		}
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   780
8350
8979cccdbed2 (svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz
parents: 8332
diff changeset
   781
		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
   782
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
   783
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   784
		SetDParam(0, pass);
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   785
		AddNewsItem(STR_B006_FLOOD_VEHICLE_DESTROYED,
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
   786
			NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_VEHICLE, NT_ACCIDENT, 0),
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   787
			v->index,
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   788
			0);
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   789
		CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   790
		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
   791
	}
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   792
}
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 43
diff changeset
   793
7731
0ddbab1c56bb (svn r11266) -Documentation: Add a few comments. Parts of BigBB's work on shores
belugas
parents: 7545
diff changeset
   794
/**
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   795
 * 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
   796
 *
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   797
 * @return Behaviour of the tile
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   798
 */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   799
static FloodingBehaviour GetFloodingBehaviour(TileIndex tile)
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   800
{
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   801
	/* FLOOD_ACTIVE:  'single-corner-raised'-coast, sea, sea-shipdepots, sea-buoys, rail with flooded halftile
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   802
	 * FLOOD_DRYUP:   coast with more than one corner raised
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   803
	 * FLOOD_PASSIVE: oilrig, dock, water-industries
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   804
	 * 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
   805
	 */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   806
	switch (GetTileType(tile)) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   807
		case MP_WATER:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   808
			if (IsCoast(tile)) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   809
				Slope tileh = GetTileSlope(tile, NULL);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   810
				return (HasBit(_active_water_slopes, tileh) ? FLOOD_ACTIVE : FLOOD_DRYUP);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   811
			} else {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   812
				return ((IsSea(tile) || (IsShipDepot(tile) && (GetShipDepotWaterOwner(tile) == OWNER_WATER))) ? FLOOD_ACTIVE : FLOOD_NONE);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   813
			}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   814
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   815
		case MP_RAILWAY:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   816
			return ((GetRailGroundType(tile) == RAIL_GROUND_WATER) ? FLOOD_ACTIVE : FLOOD_NONE);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   817
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   818
		case MP_STATION:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   819
			if (IsSeaBuoyTile(tile)) return FLOOD_ACTIVE;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   820
			if (IsOilRig(tile) || IsDock(tile)) return FLOOD_PASSIVE;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   821
			return FLOOD_NONE;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   822
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   823
		case MP_INDUSTRY:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   824
			return ((GetIndustrySpec(GetIndustryType(tile))->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0 ? FLOOD_PASSIVE : FLOOD_NONE);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   825
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   826
		default:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   827
			return FLOOD_NONE;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   828
	}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   829
}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   830
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   831
/**
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   832
 * Floods a tile.
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   833
 */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   834
static void DoFloodTile(TileIndex target)
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   835
{
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   836
	if (IsTileType(target, MP_WATER)) return;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   837
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   838
	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
   839
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   840
	_current_player = OWNER_WATER;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   841
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   842
	if (GetTileSlope(target, NULL) != SLOPE_FLAT) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   843
		/* make coast.. */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   844
		switch (GetTileType(target)) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   845
			case MP_RAILWAY: {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   846
				if (!IsPlainRailTile(target)) break;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   847
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   848
				flooded = FloodHalftile(target);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   849
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   850
				Vehicle *v = FindFloodableVehicleOnTile(target);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   851
				if (v != NULL) FloodVehicle(v);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   852
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   853
				break;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   854
			}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   855
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   856
			case MP_CLEAR:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   857
			case MP_TREES:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   858
				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
   859
					MakeShore(target);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   860
					MarkTileDirtyByTile(target);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   861
					flooded = true;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   862
				}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   863
				break;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   864
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   865
			default:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   866
				break;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   867
		}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   868
	} else {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   869
		/* Flood vehicles */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   870
		Vehicle *v = FindFloodableVehicleOnTile(target);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   871
		if (v != NULL) FloodVehicle(v);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   872
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   873
		/* flood flat tile */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   874
		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
   875
			MakeWater(target);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   876
			MarkTileDirtyByTile(target);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   877
			flooded = true;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   878
		}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   879
	}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   880
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   881
	if (flooded) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   882
		/* Mark surrounding canal tiles dirty too to avoid glitches */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   883
		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
   884
			MarkTileDirtyIfCanal(target + TileOffsByDir(dir));
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   885
		}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   886
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   887
		/* update signals if needed */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   888
		UpdateSignalsInBuffer();
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   889
	}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   890
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   891
	_current_player = OWNER_NONE;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   892
}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   893
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   894
/**
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   895
 * Drys a tile up.
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   896
 */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   897
static void DoDryUp(TileIndex tile)
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   898
{
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   899
	assert(IsTileType(tile, MP_WATER) && IsCoast(tile));
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   900
	_current_player = OWNER_WATER;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   901
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   902
	if (CmdSucceeded(DoCommand(tile, 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
   903
		MakeClear(tile, CLEAR_GRASS, 3);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   904
		MarkTileDirtyByTile(tile);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   905
	}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   906
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   907
	_current_player = OWNER_NONE;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   908
}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   909
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   910
/**
7731
0ddbab1c56bb (svn r11266) -Documentation: Add a few comments. Parts of BigBB's work on shores
belugas
parents: 7545
diff changeset
   911
 * 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
   912
 * 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
   913
 *
0ddbab1c56bb (svn r11266) -Documentation: Add a few comments. Parts of BigBB's work on shores
belugas
parents: 7545
diff changeset
   914
 * @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
   915
 */
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   916
void TileLoop_Water(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
{
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   918
	switch (GetFloodingBehaviour(tile)) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   919
		case FLOOD_ACTIVE:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   920
			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
   921
				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
   922
				if (dest == INVALID_TILE) continue;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2951
diff changeset
   923
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   924
				uint z_dest;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   925
				Slope slope_dest = (Slope)(GetFoundationSlope(dest, &z_dest) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   926
				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
   927
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   928
				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
   929
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   930
				DoFloodTile(dest);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   931
			}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   932
			break;
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   933
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   934
		case FLOOD_DRYUP: {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   935
			Slope slope_here = (Slope)(GetFoundationSlope(tile, NULL) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   936
			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
   937
			uint dir;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   938
			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
   939
				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
   940
				if (dest == INVALID_TILE) continue;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   941
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   942
				FloodingBehaviour dest_behaviour = GetFloodingBehaviour(dest);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   943
				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
   944
			}
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   945
			DoDryUp(tile);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   946
			break;
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
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   949
		default: return;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   950
	}
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   951
}
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   952
8380
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   953
void ConvertGroundTilesIntoWaterTiles()
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
	TileIndex tile;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   956
	uint z;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   957
	Slope slope;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   958
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   959
	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
   960
		slope = GetTileSlope(tile, &z);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   961
		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
   962
			/* 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
   963
			 * 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
   964
			 * during the generation. */
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   965
			switch (slope) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   966
				case SLOPE_FLAT:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   967
					MakeWater(tile);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   968
					break;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   969
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   970
				case SLOPE_N:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   971
				case SLOPE_E:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   972
				case SLOPE_S:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   973
				case SLOPE_W:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   974
					MakeShore(tile);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   975
					break;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   976
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   977
				default:
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   978
					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
   979
					uint dir;
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   980
					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
   981
						TileIndex dest = TILE_ADD(tile, TileOffsByDir((Direction)dir));
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   982
						Slope slope_dest = (Slope)(GetTileSlope(dest, NULL) & ~SLOPE_STEEP);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   983
						if (HasBit(_active_water_slopes, slope_dest)) {
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   984
							MakeShore(tile);
174326093caa (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8368
diff changeset
   985
							break;
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
					break;
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
		}
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   991
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6583
diff changeset
   994
static uint32 GetTileTrackStatus_Water(TileIndex tile, TransportType mode, uint sub_mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
{
3423
dab85d82708b (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
   996
	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
   997
0d77cd42f6e6 (svn r5606) Replace some magic numbers by proper TrackBits enums and macros
tron
parents: 4101
diff changeset
   998
	TrackBits ts;
0d77cd42f6e6 (svn r5606) Replace some magic numbers by proper TrackBits enums and macros
tron
parents: 4101
diff changeset
   999
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1000
	if (mode != TRANSPORT_WATER) return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
3423
dab85d82708b (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
  1002
	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
  1003
		case WATER_TILE_CLEAR: ts = TRACK_BIT_ALL; break;
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
  1004
		case WATER_TILE_COAST: ts = (TrackBits)coast_tracks[GetTileSlope(tile, NULL) & 0xF]; break;
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
  1005
		case WATER_TILE_LOCK:  ts = AxisToTrackBits(DiagDirToAxis(GetLockDirection(tile))); break;
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
  1006
		case WATER_TILE_DEPOT: ts = AxisToTrackBits(GetShipDepotAxis(tile)); break;
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
  1007
		case WATER_TILE_RIVER: ts = (GetTileSlope(tile, NULL) == SLOPE_FLAT) ? TRACK_BIT_ALL : TRACK_BIT_NONE; break;
3423
dab85d82708b (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
  1008
		default: return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
	}
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1010
	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
  1011
		/* 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
  1012
		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
  1013
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1014
	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
  1015
		/* 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
  1016
		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
  1017
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1018
	return ts * 0x101;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
  1021
static void ClickTile_Water(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
{
6181
2d0ac0598453 (svn r8953) -Codechange: make the names of enums of WaterTileType consistent with respect to RailTileType and RoadTileType.
rubidium
parents: 6160
diff changeset
  1023
	if (GetWaterTileType(tile) == WATER_TILE_DEPOT) {
3423
dab85d82708b (svn r4250) -Codechange: Further use of map accessors for water tiles
celestar
parents: 3422
diff changeset
  1024
		TileIndex tile2 = GetOtherShipDepotTile(tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 168
diff changeset
  1025
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
  1026
		ShowDepotWindow(tile < tile2 ? tile : tile2, VEH_SHIP);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
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
  1030
static void ChangeTileOwner_Water(TileIndex tile, PlayerID old_player, PlayerID new_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
{
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  1032
	if (!IsTileOwner(tile, old_player)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
4848
45f848b46222 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4638
diff changeset
  1034
	if (new_player != PLAYER_SPECTATOR) {
1902
86b7fb11f938 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
  1035
		SetTileOwner(tile, new_player);
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
  1036
	} else if (IsShipDepot(tile)) {
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
  1037
		DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
	} else {
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
  1039
		SetTileOwner(tile, OWNER_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8116
diff changeset
  1043
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
  1044
{
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5954
diff changeset
  1045
	return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7443
diff changeset
  1048
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
  1049
{
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7443
diff changeset
  1050
	/* Canals can't be terraformed */
7739
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7731
diff changeset
  1051
	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
  1052
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7443
diff changeset
  1053
	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
  1054
}
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7443
diff changeset
  1055
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1057
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
  1058
	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
  1059
	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
  1060
	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
  1061
	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
  1062
	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
  1063
	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
  1064
	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
  1065
	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
  1066
	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
  1067
	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
  1068
	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
  1069
	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
  1070
	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
  1071
	TerraformTile_Water,      /* terraform_tile_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
};