2005-07-24 15:12:37 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-04-06 05:10:19 +01:00
|
|
|
/** @file water_cmd.cpp */
|
|
|
|
|
2004-08-09 18:04:08 +01:00
|
|
|
#include "stdafx.h"
|
2005-06-02 20:30:21 +01:00
|
|
|
#include "openttd.h"
|
2006-03-13 12:55:20 +00:00
|
|
|
#include "bridge_map.h"
|
2007-02-26 18:25:03 +00:00
|
|
|
#include "bridge.h"
|
2007-02-24 09:42:39 +00:00
|
|
|
#include "cmd_helper.h"
|
2006-03-26 20:20:15 +01:00
|
|
|
#include "station_map.h"
|
2007-12-21 22:50:51 +00:00
|
|
|
#include "tile_cmd.h"
|
2007-04-12 14:07:15 +01:00
|
|
|
#include "landscape.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "viewport_func.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2004-08-09 18:04:08 +01:00
|
|
|
#include "town.h"
|
2004-09-03 18:57:27 +01:00
|
|
|
#include "news.h"
|
2005-02-06 10:18:47 +00:00
|
|
|
#include "depot.h"
|
2005-05-03 00:59:11 +01:00
|
|
|
#include "vehicle_gui.h"
|
2005-11-18 23:41:03 +00:00
|
|
|
#include "train.h"
|
2007-06-11 15:00:16 +01:00
|
|
|
#include "roadveh.h"
|
2007-12-19 23:26:02 +00:00
|
|
|
#include "water.h"
|
2006-03-01 21:00:44 +00:00
|
|
|
#include "water_map.h"
|
2007-08-31 20:46:45 +01:00
|
|
|
#include "industry_map.h"
|
2006-12-02 09:54:49 +00:00
|
|
|
#include "newgrf.h"
|
2007-05-06 19:14:33 +01:00
|
|
|
#include "newgrf_canal.h"
|
2007-08-02 23:33:53 +01:00
|
|
|
#include "misc/autoptr.hpp"
|
2007-11-10 01:17:15 +00:00
|
|
|
#include "transparency.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "functions.h"
|
|
|
|
#include "window_func.h"
|
2007-12-27 13:35:39 +00:00
|
|
|
#include "vehicle_func.h"
|
2007-12-29 09:24:26 +00:00
|
|
|
#include "sound_func.h"
|
2008-01-07 00:57:19 +00:00
|
|
|
#include "variables.h"
|
2008-01-12 14:10:35 +00:00
|
|
|
#include "player_func.h"
|
2008-01-13 14:37:30 +00:00
|
|
|
#include "settings_type.h"
|
2008-01-22 17:48:08 +00:00
|
|
|
#include "clear_map.h"
|
2004-09-03 18:57:27 +01:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/sprites.h"
|
|
|
|
#include "table/strings.h"
|
2005-08-01 17:31:19 +01:00
|
|
|
|
2008-01-22 17:48:08 +00:00
|
|
|
/**
|
|
|
|
* Describes the behaviour of a tile during flooding.
|
|
|
|
*/
|
|
|
|
enum FloodingBehaviour {
|
|
|
|
FLOOD_NONE, ///< The tile does not flood neighboured tiles.
|
|
|
|
FLOOD_ACTIVE, ///< The tile floods neighboured tiles.
|
|
|
|
FLOOD_PASSIVE, ///< The tile does not actively flood neighboured tiles, but it prevents them from drying up.
|
|
|
|
FLOOD_DRYUP, ///< The tile drys up if it is not constantly flooded from neighboured tiles.
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Describes from which directions a specific slope can be flooded (if the tile is floodable at all).
|
|
|
|
*/
|
|
|
|
static const uint8 _flood_from_dirs[] = {
|
|
|
|
(1 << DIR_NW) | (1 << DIR_SW) | (1 << DIR_SE) | (1 << DIR_NE), // SLOPE_FLAT
|
|
|
|
(1 << DIR_NE) | (1 << DIR_SE), // SLOPE_W
|
|
|
|
(1 << DIR_NW) | (1 << DIR_NE), // SLOPE_S
|
|
|
|
(1 << DIR_NE), // SLOPE_SW
|
|
|
|
(1 << DIR_NW) | (1 << DIR_SW), // SLOPE_E
|
|
|
|
0, // SLOPE_EW
|
|
|
|
(1 << DIR_NW), // SLOPE_SE
|
|
|
|
(1 << DIR_N ) | (1 << DIR_NW) | (1 << DIR_NE), // SLOPE_WSE, SLOPE_STEEP_S
|
|
|
|
(1 << DIR_SW) | (1 << DIR_SE), // SLOPE_N
|
|
|
|
(1 << DIR_SE), // SLOPE_NW
|
|
|
|
0, // SLOPE_NS
|
|
|
|
(1 << DIR_E ) | (1 << DIR_NE) | (1 << DIR_SE), // SLOPE_NWS, SLOPE_STEEP_W
|
|
|
|
(1 << DIR_SW), // SLOPE_NE
|
|
|
|
(1 << DIR_S ) | (1 << DIR_SW) | (1 << DIR_SE), // SLOPE_ENW, SLOPE_STEEP_N
|
|
|
|
(1 << DIR_W ) | (1 << DIR_SW) | (1 << DIR_NW), // SLOPE_SEN, SLOPE_STEEP_E
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Slopes that contain flat water and not only shore.
|
|
|
|
*/
|
|
|
|
static const uint32 _active_water_slopes = (1 << SLOPE_FLAT) | (1 << SLOPE_W) | (1 << SLOPE_S) | (1 << SLOPE_E) | (1 << SLOPE_N);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-11-24 08:45:04 +00:00
|
|
|
/**
|
|
|
|
* Makes a tile canal or water depending on the surroundings.
|
|
|
|
* This as for example docks and shipdepots do not store
|
|
|
|
* whether the tile used to be canal or 'normal' water.
|
|
|
|
* @param t the tile to change.
|
|
|
|
* @param o the owner of the new tile.
|
|
|
|
*/
|
|
|
|
void MakeWaterOrCanalDependingOnSurroundings(TileIndex t, Owner o)
|
|
|
|
{
|
|
|
|
assert(GetTileSlope(t, NULL) == SLOPE_FLAT);
|
|
|
|
|
2007-12-06 20:48:15 +00:00
|
|
|
/* Mark tile dirty in all cases */
|
|
|
|
MarkTileDirtyByTile(t);
|
|
|
|
|
2007-11-24 08:45:04 +00:00
|
|
|
/* Non-sealevel -> canal */
|
|
|
|
if (TileHeight(t) != 0) {
|
2008-01-20 18:30:53 +00:00
|
|
|
MakeCanal(t, o, Random());
|
2007-11-24 08:45:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool has_water = false;
|
|
|
|
bool has_canal = false;
|
|
|
|
|
|
|
|
for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
|
|
|
|
TileIndex neighbour = TileAddByDiagDir(t, dir);
|
|
|
|
if (IsTileType(neighbour, MP_WATER)) {
|
2007-12-07 21:14:54 +00:00
|
|
|
has_water |= IsSea(neighbour) || IsCoast(neighbour) || (IsShipDepot(neighbour) && GetShipDepotWaterOwner(neighbour) == OWNER_WATER);
|
|
|
|
has_canal |= IsCanal(neighbour) || (IsShipDepot(neighbour) && GetShipDepotWaterOwner(neighbour) != OWNER_WATER);
|
2007-11-24 08:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (has_canal || !has_water) {
|
2008-01-20 18:30:53 +00:00
|
|
|
MakeCanal(t, o, Random());
|
2007-11-24 08:45:04 +00:00
|
|
|
} else {
|
|
|
|
MakeWater(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-09 23:33:00 +01:00
|
|
|
/** Build a ship depot.
|
2006-04-10 08:15:58 +01:00
|
|
|
* @param tile tile where ship depot is built
|
2007-04-06 05:10:19 +01:00
|
|
|
* @param flags type of operation
|
2007-02-24 09:42:39 +00:00
|
|
|
* @param p1 bit 0 depot orientation (Axis)
|
2005-05-09 23:33:00 +01:00
|
|
|
* @param p2 unused
|
2004-08-09 18:04:08 +01:00
|
|
|
*/
|
2007-06-18 11:48:15 +01:00
|
|
|
CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2006-04-10 08:15:58 +01:00
|
|
|
TileIndex tile2;
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2008-01-09 16:55:48 +00:00
|
|
|
CommandCost ret;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-02-24 09:42:39 +00:00
|
|
|
Axis axis = Extract<Axis, 0>(p1);
|
|
|
|
|
|
|
|
tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-10-16 20:48:58 +01:00
|
|
|
if (!IsWaterTile(tile) || !IsWaterTile(tile2))
|
2004-08-09 18:04:08 +01:00
|
|
|
return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER);
|
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
|
|
|
|
|
2007-12-07 21:14:54 +00:00
|
|
|
Owner o1 = GetTileOwner(tile);
|
|
|
|
Owner o2 = GetTileOwner(tile2);
|
2006-04-10 08:15:58 +01:00
|
|
|
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2005-05-09 23:33:00 +01:00
|
|
|
if (CmdFailed(ret)) return CMD_ERROR;
|
2006-04-10 08:15:58 +01:00
|
|
|
ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2005-05-09 23:33:00 +01:00
|
|
|
if (CmdFailed(ret)) return CMD_ERROR;
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2007-08-02 23:33:53 +01:00
|
|
|
Depot *depot = new Depot(tile);
|
2005-05-09 23:33:00 +01:00
|
|
|
if (depot == NULL) return CMD_ERROR;
|
2007-08-02 23:33:53 +01:00
|
|
|
AutoPtrT<Depot> d_auto_delete = depot;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2005-02-06 10:18:47 +00:00
|
|
|
depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-12-07 21:14:54 +00:00
|
|
|
MakeShipDepot(tile, _current_player, DEPOT_NORTH, axis, o1);
|
|
|
|
MakeShipDepot(tile2, _current_player, DEPOT_SOUTH, axis, o2);
|
2006-03-30 12:11:35 +01:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
MarkTileDirtyByTile(tile2);
|
2007-08-02 23:33:53 +01:00
|
|
|
d_auto_delete.Detach();
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2008-01-09 16:55:48 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_ship_depot);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2007-12-19 02:41:25 +00:00
|
|
|
void MakeWaterOrCanalDependingOnOwner(TileIndex tile, Owner o)
|
2007-12-07 21:14:54 +00:00
|
|
|
{
|
|
|
|
if (o == OWNER_WATER) {
|
|
|
|
MakeWater(tile);
|
|
|
|
} else {
|
2008-01-20 18:30:53 +00:00
|
|
|
MakeCanal(tile, o, Random());
|
2007-12-07 21:14:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-18 11:48:15 +01:00
|
|
|
static CommandCost RemoveShipDepot(TileIndex tile, uint32 flags)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2005-06-24 13:38:35 +01:00
|
|
|
TileIndex tile2;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2006-03-30 12:21:36 +01:00
|
|
|
if (!IsShipDepot(tile)) return CMD_ERROR;
|
2006-02-01 06:32:03 +00:00
|
|
|
if (!CheckTileOwnership(tile)) return CMD_ERROR;
|
2007-10-19 23:46:55 +01:00
|
|
|
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2006-03-30 12:21:36 +01:00
|
|
|
tile2 = GetOtherShipDepotTile(tile);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-10-19 23:46:55 +01:00
|
|
|
if (!EnsureNoVehicleOnGround(tile2)) return CMD_ERROR;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2006-03-30 12:21:36 +01:00
|
|
|
/* Kill the depot, which is registered at the northernmost tile. Use that one */
|
2007-08-02 23:33:53 +01:00
|
|
|
delete GetDepotByTile(tile2 < tile ? tile2 : tile);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-12-07 21:14:54 +00:00
|
|
|
MakeWaterOrCanalDependingOnOwner(tile, GetShipDepotWaterOwner(tile));
|
|
|
|
MakeWaterOrCanalDependingOnOwner(tile2, GetShipDepotWaterOwner(tile2));
|
2006-03-01 21:00:44 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
MarkTileDirtyByTile(tile2);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2008-01-09 16:55:48 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_ship_depot);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2007-04-06 05:10:19 +01:00
|
|
|
/** build a shiplift */
|
2007-06-18 11:48:15 +01:00
|
|
|
static CommandCost DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2007-06-18 11:48:15 +01:00
|
|
|
CommandCost ret;
|
2004-08-09 18:04:08 +01:00
|
|
|
int delta;
|
|
|
|
|
2007-04-06 05:10:19 +01:00
|
|
|
/* middle tile */
|
2006-04-10 08:15:58 +01:00
|
|
|
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2005-12-10 12:05:39 +00:00
|
|
|
if (CmdFailed(ret)) return CMD_ERROR;
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2006-09-06 00:21:41 +01:00
|
|
|
delta = TileOffsByDiagDir(dir);
|
2007-04-06 05:10:19 +01:00
|
|
|
/* lower tile */
|
2006-04-10 08:15:58 +01:00
|
|
|
ret = DoCommand(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2005-12-10 12:05:39 +00:00
|
|
|
if (CmdFailed(ret)) return CMD_ERROR;
|
2006-04-23 14:48:16 +01:00
|
|
|
if (GetTileSlope(tile - delta, NULL) != SLOPE_FLAT) {
|
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-04-06 05:10:19 +01:00
|
|
|
/* upper tile */
|
2006-04-10 08:15:58 +01:00
|
|
|
ret = DoCommand(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2005-12-10 12:05:39 +00:00
|
|
|
if (CmdFailed(ret)) return CMD_ERROR;
|
2006-04-23 14:48:16 +01:00
|
|
|
if (GetTileSlope(tile + delta, NULL) != SLOPE_FLAT) {
|
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if ((MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) ||
|
|
|
|
(MayHaveBridgeAbove(tile - delta) && IsBridgeAbove(tile - delta)) ||
|
|
|
|
(MayHaveBridgeAbove(tile + delta) && IsBridgeAbove(tile + delta))) {
|
|
|
|
return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
|
|
|
|
}
|
|
|
|
|
2004-08-09 18:04:08 +01:00
|
|
|
if (flags & DC_EXEC) {
|
2006-06-03 16:10:39 +01:00
|
|
|
MakeLock(tile, _current_player, dir);
|
2006-03-30 12:11:35 +01:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
MarkTileDirtyByTile(tile - delta);
|
|
|
|
MarkTileDirtyByTile(tile + delta);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2008-01-09 16:55:48 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 22 >> 3);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2007-06-18 11:48:15 +01:00
|
|
|
static CommandCost RemoveShiplift(TileIndex tile, uint32 flags)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2006-09-06 00:21:41 +01:00
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile));
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-07-16 22:00:40 +01:00
|
|
|
if (!CheckTileOwnership(tile) && GetTileOwner(tile) != OWNER_NONE) return CMD_ERROR;
|
2006-06-03 16:10:39 +01:00
|
|
|
|
2007-04-06 05:10:19 +01:00
|
|
|
/* make sure no vehicle is on the tile. */
|
2007-10-19 23:46:55 +01:00
|
|
|
if (!EnsureNoVehicleOnGround(tile) || !EnsureNoVehicleOnGround(tile + delta) || !EnsureNoVehicleOnGround(tile - delta))
|
2004-08-09 18:04:08 +01:00
|
|
|
return CMD_ERROR;
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
DoClearSquare(tile);
|
2007-11-24 08:45:04 +00:00
|
|
|
MakeWaterOrCanalDependingOnSurroundings(tile + delta, _current_player);
|
|
|
|
MakeWaterOrCanalDependingOnSurroundings(tile - delta, _current_player);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2008-01-09 16:55:48 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 2);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2007-09-09 11:13:17 +01:00
|
|
|
/**
|
|
|
|
* Marks the tiles around a tile as dirty.
|
|
|
|
*
|
|
|
|
* This functions marks the tiles around a given tile as dirty for repaint.
|
|
|
|
*
|
|
|
|
* @param tile The center of the tile where all other tiles are marked as dirty
|
|
|
|
* @ingroup dirty
|
|
|
|
* @see TerraformAddDirtyTileAround
|
|
|
|
*/
|
2005-06-24 13:38:35 +01:00
|
|
|
static void MarkTilesAroundDirty(TileIndex tile)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
|
|
|
MarkTileDirtyByTile(TILE_ADDXY(tile, 0, 1));
|
|
|
|
MarkTileDirtyByTile(TILE_ADDXY(tile, 0, -1));
|
|
|
|
MarkTileDirtyByTile(TILE_ADDXY(tile, 1, 0));
|
|
|
|
MarkTileDirtyByTile(TILE_ADDXY(tile, -1, 0));
|
|
|
|
}
|
|
|
|
|
2005-05-13 00:46:01 +01:00
|
|
|
/** Builds a lock (ship-lift)
|
2006-04-10 08:15:58 +01:00
|
|
|
* @param tile tile where to place the lock
|
2007-04-06 05:10:19 +01:00
|
|
|
* @param flags type of operation
|
2005-05-13 00:46:01 +01:00
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2007-06-18 11:48:15 +01:00
|
|
|
CommandCost CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2006-03-08 06:55:33 +00:00
|
|
|
DiagDirection dir;
|
2005-01-04 17:11:03 +00:00
|
|
|
|
2006-03-08 06:55:33 +00:00
|
|
|
switch (GetTileSlope(tile, NULL)) {
|
2006-04-23 14:48:16 +01:00
|
|
|
case SLOPE_SW: dir = DIAGDIR_SW; break;
|
|
|
|
case SLOPE_SE: dir = DIAGDIR_SE; break;
|
|
|
|
case SLOPE_NW: dir = DIAGDIR_NW; break;
|
|
|
|
case SLOPE_NE: dir = DIAGDIR_NE; break;
|
2006-03-08 06:55:33 +00:00
|
|
|
default: return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
2005-05-13 00:46:01 +01:00
|
|
|
}
|
2008-01-23 08:47:49 +00:00
|
|
|
|
|
|
|
/* Disallow building of locks on river rapids */
|
|
|
|
if (IsRiverTile(tile)) return_cmd_error(STR_0239_SITE_UNSUITABLE);
|
|
|
|
|
2006-03-08 06:55:33 +00:00
|
|
|
return DoBuildShiplift(tile, dir, flags);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2005-05-13 00:46:01 +01:00
|
|
|
/** Build a piece of canal.
|
2006-04-10 08:15:58 +01:00
|
|
|
* @param tile end tile of stretch-dragging
|
2007-04-06 05:10:19 +01:00
|
|
|
* @param flags type of operation
|
2005-05-13 00:46:01 +01:00
|
|
|
* @param p1 start tile of stretch-dragging
|
2007-03-10 21:44:22 +00:00
|
|
|
* @param p2 ctrl pressed - toggles ocean / canals at sealevel (ocean only allowed in the scenario editor)
|
2005-05-13 00:46:01 +01:00
|
|
|
*/
|
2007-06-18 11:48:15 +01:00
|
|
|
CommandCost CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2008-01-09 16:55:48 +00:00
|
|
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
- Fix: 'L' no longer opens ingame terraform bar in scenario editor bar, but the land generator one
- Feature: [ 1095110 ] Create Lake and draggable Create Desert tools (initial implementation GoneWacko), also added sticky buttons to land generator and town generator
- CodeChange: moved around some of the draggable tools, demystifying them
- CodeChange: change CmdBuildCanal to allow for XANDY dragging not only X or Y (only scenario editor)
- CodeChange: add some more enums to sprites.
- TODO: merge most of the ingame and scenario editor land terraform code. This can only be done after OnClickButton function is changed so it also includes the backreference to the widget being clicked, postponed to after 0.4.0
2005-04-03 00:05:09 +01:00
|
|
|
int size_x, size_y;
|
2006-04-10 08:15:58 +01:00
|
|
|
int x;
|
|
|
|
int y;
|
2005-05-13 00:46:01 +01:00
|
|
|
int sx, sy;
|
|
|
|
|
2006-01-30 17:18:45 +00:00
|
|
|
if (p1 >= MapSize()) return CMD_ERROR;
|
2008-01-19 17:00:54 +00:00
|
|
|
|
2007-03-10 21:44:22 +00:00
|
|
|
/* Outside of the editor you can only build canals, not oceans */
|
2008-01-19 18:24:20 +00:00
|
|
|
if (p2 != 0 && _game_mode != GM_EDITOR) return CMD_ERROR;
|
2005-05-13 00:46:01 +01:00
|
|
|
|
2006-04-10 08:15:58 +01:00
|
|
|
x = TileX(tile);
|
|
|
|
y = TileY(tile);
|
2005-05-13 00:46:01 +01:00
|
|
|
sx = TileX(p1);
|
|
|
|
sy = TileY(p1);
|
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
- Fix: 'L' no longer opens ingame terraform bar in scenario editor bar, but the land generator one
- Feature: [ 1095110 ] Create Lake and draggable Create Desert tools (initial implementation GoneWacko), also added sticky buttons to land generator and town generator
- CodeChange: moved around some of the draggable tools, demystifying them
- CodeChange: change CmdBuildCanal to allow for XANDY dragging not only X or Y (only scenario editor)
- CodeChange: add some more enums to sprites.
- TODO: merge most of the ingame and scenario editor land terraform code. This can only be done after OnClickButton function is changed so it also includes the backreference to the widget being clicked, postponed to after 0.4.0
2005-04-03 00:05:09 +01:00
|
|
|
|
2007-02-22 08:43:02 +00:00
|
|
|
if (x < sx) Swap(x, sx);
|
|
|
|
if (y < sy) Swap(y, sy);
|
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
- Fix: 'L' no longer opens ingame terraform bar in scenario editor bar, but the land generator one
- Feature: [ 1095110 ] Create Lake and draggable Create Desert tools (initial implementation GoneWacko), also added sticky buttons to land generator and town generator
- CodeChange: moved around some of the draggable tools, demystifying them
- CodeChange: change CmdBuildCanal to allow for XANDY dragging not only X or Y (only scenario editor)
- CodeChange: add some more enums to sprites.
- TODO: merge most of the ingame and scenario editor land terraform code. This can only be done after OnClickButton function is changed so it also includes the backreference to the widget being clicked, postponed to after 0.4.0
2005-04-03 00:05:09 +01:00
|
|
|
size_x = (x - sx) + 1;
|
|
|
|
size_y = (y - sy) + 1;
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2005-05-13 00:46:01 +01:00
|
|
|
/* Outside the editor you can only drag canals, and not areas */
|
|
|
|
if (_game_mode != GM_EDITOR && (sx != x && sy != y)) return CMD_ERROR;
|
|
|
|
|
2005-06-25 17:44:57 +01:00
|
|
|
BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
|
2007-06-18 11:48:15 +01:00
|
|
|
CommandCost ret;
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2008-01-19 17:00:54 +00:00
|
|
|
Slope slope = GetTileSlope(tile, NULL);
|
|
|
|
if (slope != SLOPE_FLAT && (p2 != 2 || (slope != SLOPE_NW && slope != SLOPE_NE && slope != SLOPE_SW && slope != SLOPE_SE))) {
|
2006-04-23 14:48:16 +01:00
|
|
|
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
|
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-04-06 05:10:19 +01:00
|
|
|
/* can't make water of water! */
|
2008-01-19 17:00:54 +00:00
|
|
|
if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || p2 == 1)) continue;
|
2006-03-12 12:19:25 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
|
if (CmdFailed(ret)) return ret;
|
2007-06-18 20:53:50 +01:00
|
|
|
cost.AddCost(ret);
|
2006-06-07 20:35:21 +01:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2008-01-19 17:00:54 +00:00
|
|
|
if (TileHeight(tile) == 0 && p2 == 1) {
|
2006-12-27 12:38:02 +00:00
|
|
|
MakeWater(tile);
|
2008-01-19 17:00:54 +00:00
|
|
|
} else if (p2 == 2) {
|
2008-01-20 18:30:53 +00:00
|
|
|
MakeRiver(tile, Random());
|
2006-12-27 12:38:02 +00:00
|
|
|
} else {
|
2008-01-20 18:30:53 +00:00
|
|
|
MakeCanal(tile, _current_player, Random());
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
2006-03-13 12:55:20 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
MarkTilesAroundDirty(tile);
|
|
|
|
}
|
2006-03-12 12:19:25 +00:00
|
|
|
|
2007-06-18 20:53:50 +01:00
|
|
|
cost.AddCost(_price.clear_water);
|
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
- Fix: 'L' no longer opens ingame terraform bar in scenario editor bar, but the land generator one
- Feature: [ 1095110 ] Create Lake and draggable Create Desert tools (initial implementation GoneWacko), also added sticky buttons to land generator and town generator
- CodeChange: moved around some of the draggable tools, demystifying them
- CodeChange: change CmdBuildCanal to allow for XANDY dragging not only X or Y (only scenario editor)
- CodeChange: add some more enums to sprites.
- TODO: merge most of the ingame and scenario editor land terraform code. This can only be done after OnClickButton function is changed so it also includes the backreference to the widget being clicked, postponed to after 0.4.0
2005-04-03 00:05:09 +01:00
|
|
|
} END_TILE_LOOP(tile, size_x, size_y, 0);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-06-18 20:53:50 +01:00
|
|
|
if (cost.GetCost() == 0) {
|
2006-03-12 12:19:25 +00:00
|
|
|
return_cmd_error(STR_1007_ALREADY_BUILT);
|
|
|
|
} else {
|
|
|
|
return cost;
|
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2007-06-18 11:48:15 +01:00
|
|
|
static CommandCost ClearTile_Water(TileIndex tile, byte flags)
|
2005-06-24 13:38:35 +01:00
|
|
|
{
|
2006-04-03 11:50:54 +01:00
|
|
|
switch (GetWaterTileType(tile)) {
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_CLEAR:
|
2008-01-19 17:00:54 +00:00
|
|
|
case WATER_TILE_RIVER:
|
2006-04-03 11:50:54 +01:00
|
|
|
if (flags & DC_NO_WATER) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-04-06 05:10:19 +01:00
|
|
|
/* Make sure it's not an edge tile. */
|
2007-11-24 10:38:43 +00:00
|
|
|
if (!IsInsideMM(TileX(tile), 1, MapMaxX() - 1) ||
|
|
|
|
!IsInsideMM(TileY(tile), 1, MapMaxY() - 1)) {
|
2006-04-03 11:50:54 +01:00
|
|
|
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP);
|
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-08-31 21:03:50 +01:00
|
|
|
/* Make sure no vehicle is on the tile */
|
2007-10-19 23:46:55 +01:00
|
|
|
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
2007-08-31 21:03:50 +01:00
|
|
|
|
2007-07-16 22:00:40 +01:00
|
|
|
if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE && !CheckTileOwnership(tile)) return CMD_ERROR;
|
2006-06-03 16:10:39 +01:00
|
|
|
|
2006-02-01 06:32:03 +00:00
|
|
|
if (flags & DC_EXEC) DoClearSquare(tile);
|
2008-01-09 16:55:48 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water);
|
2006-04-04 07:01:45 +01:00
|
|
|
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_COAST: {
|
2006-04-23 14:48:16 +01:00
|
|
|
Slope slope = GetTileSlope(tile, NULL);
|
2006-04-04 07:01:45 +01:00
|
|
|
|
2007-04-06 05:10:19 +01:00
|
|
|
/* Make sure no vehicle is on the tile */
|
2007-10-19 23:46:55 +01:00
|
|
|
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
2006-04-04 07:01:45 +01:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) DoClearSquare(tile);
|
2006-04-23 14:48:16 +01:00
|
|
|
if (slope == SLOPE_N || slope == SLOPE_E || slope == SLOPE_S || slope == SLOPE_W) {
|
2008-01-09 16:55:48 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water);
|
2006-04-04 07:01:45 +01:00
|
|
|
} else {
|
2008-01-09 16:55:48 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_roughland);
|
2006-04-03 11:50:54 +01:00
|
|
|
}
|
2006-04-04 07:01:45 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_LOCK: {
|
2006-04-04 07:01:45 +01:00
|
|
|
static const TileIndexDiffC _shiplift_tomiddle_offs[] = {
|
|
|
|
{ 0, 0}, {0, 0}, { 0, 0}, {0, 0}, // middle
|
|
|
|
{-1, 0}, {0, 1}, { 1, 0}, {0, -1}, // lower
|
|
|
|
{ 1, 0}, {0, -1}, {-1, 0}, {0, 1}, // upper
|
|
|
|
};
|
|
|
|
|
|
|
|
if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
|
|
|
|
if (_current_player == OWNER_WATER) return CMD_ERROR;
|
2007-04-06 05:10:19 +01:00
|
|
|
/* move to the middle tile.. */
|
2006-04-04 07:01:45 +01:00
|
|
|
return RemoveShiplift(tile + ToTileIndexDiff(_shiplift_tomiddle_offs[GetSection(tile)]), flags);
|
|
|
|
}
|
|
|
|
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_DEPOT:
|
2006-04-03 11:50:54 +01:00
|
|
|
if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
|
|
|
|
return RemoveShipDepot(tile, flags);
|
2006-04-03 19:12:42 +01:00
|
|
|
|
2006-04-04 07:01:45 +01:00
|
|
|
default:
|
|
|
|
NOT_REACHED();
|
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2007-04-06 05:10:19 +01:00
|
|
|
/** return true if a tile is a water tile. */
|
2005-01-17 09:41:46 +00:00
|
|
|
static bool IsWateredTile(TileIndex tile)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2005-01-29 15:12:40 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2006-06-07 20:35:21 +01:00
|
|
|
case MP_WATER:
|
2006-06-28 18:33:04 +01:00
|
|
|
if (!IsCoast(tile)) return true;
|
|
|
|
|
|
|
|
switch (GetTileSlope(tile, NULL)) {
|
|
|
|
case SLOPE_W:
|
|
|
|
case SLOPE_S:
|
|
|
|
case SLOPE_E:
|
|
|
|
case SLOPE_N:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2006-06-07 20:35:21 +01:00
|
|
|
|
2008-01-13 17:55:00 +00:00
|
|
|
case MP_RAILWAY: return GetRailGroundType(tile) == RAIL_GROUND_WATER;
|
2007-08-31 20:46:45 +01:00
|
|
|
case MP_STATION: return IsOilRig(tile) || IsDock(tile) || IsBuoy(tile);
|
|
|
|
case MP_INDUSTRY: return (GetIndustrySpec(GetIndustryType(tile))->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0;
|
|
|
|
default: return false;
|
2005-01-17 09:41:46 +00:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2008-01-19 17:00:54 +00:00
|
|
|
static void DrawWaterEdges(SpriteID base, TileIndex tile)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
|
|
|
uint wa;
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2007-04-06 05:10:19 +01:00
|
|
|
/* determine the edges around with water. */
|
2007-08-31 20:46:45 +01:00
|
|
|
wa = IsWateredTile(TILE_ADDXY(tile, -1, 0)) << 0;
|
|
|
|
wa += IsWateredTile(TILE_ADDXY(tile, 0, 1)) << 1;
|
|
|
|
wa += IsWateredTile(TILE_ADDXY(tile, 1, 0)) << 2;
|
|
|
|
wa += IsWateredTile(TILE_ADDXY(tile, 0, -1)) << 3;
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2008-01-19 17:00:54 +00:00
|
|
|
if (!(wa & 1)) DrawGroundSprite(base, PAL_NONE);
|
|
|
|
if (!(wa & 2)) DrawGroundSprite(base + 1, PAL_NONE);
|
|
|
|
if (!(wa & 4)) DrawGroundSprite(base + 2, PAL_NONE);
|
|
|
|
if (!(wa & 8)) DrawGroundSprite(base + 3, PAL_NONE);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-04-06 05:10:19 +01:00
|
|
|
/* right corner */
|
2006-02-06 09:18:04 +00:00
|
|
|
switch (wa & 0x03) {
|
2008-01-19 17:00:54 +00:00
|
|
|
case 0: DrawGroundSprite(base + 4, PAL_NONE); break;
|
|
|
|
case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(base + 8, PAL_NONE); break;
|
2006-02-06 09:18:04 +00:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-04-06 05:10:19 +01:00
|
|
|
/* bottom corner */
|
2006-02-06 09:18:04 +00:00
|
|
|
switch (wa & 0x06) {
|
2008-01-19 17:00:54 +00:00
|
|
|
case 0: DrawGroundSprite(base + 5, PAL_NONE); break;
|
|
|
|
case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(base + 9, PAL_NONE); break;
|
2006-02-06 09:18:04 +00:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-04-06 05:10:19 +01:00
|
|
|
/* left corner */
|
2006-02-06 09:18:04 +00:00
|
|
|
switch (wa & 0x0C) {
|
2008-01-19 17:00:54 +00:00
|
|
|
case 0: DrawGroundSprite(base + 6, PAL_NONE); break;
|
|
|
|
case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(base + 10, PAL_NONE); break;
|
2006-02-06 09:18:04 +00:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-04-06 05:10:19 +01:00
|
|
|
/* upper corner */
|
2006-02-06 09:18:04 +00:00
|
|
|
switch (wa & 0x09) {
|
2008-01-19 17:00:54 +00:00
|
|
|
case 0: DrawGroundSprite(base + 7, PAL_NONE); break;
|
|
|
|
case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(base + 11, PAL_NONE); break;
|
2006-02-06 09:18:04 +00:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2008-01-19 17:00:54 +00:00
|
|
|
/** draw a canal styled water tile with dikes around */
|
|
|
|
void DrawCanalWater(TileIndex tile)
|
|
|
|
{
|
|
|
|
/* Test for custom graphics, else use the default */
|
|
|
|
SpriteID dikes_base = GetCanalSprite(CF_DIKES, tile);
|
|
|
|
if (dikes_base == 0) dikes_base = SPR_CANAL_DIKES_BASE;
|
|
|
|
|
|
|
|
DrawWaterEdges(dikes_base, tile);
|
|
|
|
}
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct LocksDrawTileStruct {
|
2004-08-09 18:04:08 +01:00
|
|
|
int8 delta_x, delta_y, delta_z;
|
|
|
|
byte width, height, depth;
|
|
|
|
SpriteID image;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-09 18:04:08 +01:00
|
|
|
|
|
|
|
#include "table/water_land.h"
|
|
|
|
|
2005-09-18 21:56:44 +01:00
|
|
|
static void DrawWaterStuff(const TileInfo *ti, const WaterDrawTileStruct *wdts,
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID palette, uint base
|
2005-02-22 18:27:57 +00:00
|
|
|
)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2007-05-06 19:14:33 +01:00
|
|
|
SpriteID image;
|
|
|
|
SpriteID water_base = GetCanalSprite(CF_WATERSLOPE, ti->tile);
|
|
|
|
SpriteID locks_base = GetCanalSprite(CF_LOCKS, ti->tile);
|
|
|
|
|
|
|
|
/* If no custom graphics, use defaults */
|
2007-11-15 07:42:25 +00:00
|
|
|
if (water_base == 0) water_base = SPR_CANALS_BASE;
|
2007-05-06 19:14:33 +01:00
|
|
|
if (locks_base == 0) {
|
2007-11-15 07:42:25 +00:00
|
|
|
locks_base = SPR_SHIPLIFT_BASE;
|
2007-05-06 19:14:33 +01:00
|
|
|
} else {
|
|
|
|
/* If using custom graphics, ignore the variation on height */
|
|
|
|
base = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
image = wdts++->image;
|
|
|
|
if (image < 4) image += water_base;
|
|
|
|
DrawGroundSprite(image, PAL_NONE);
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2005-02-22 18:27:57 +00:00
|
|
|
for (; wdts->delta_x != 0x80; wdts++) {
|
2007-07-26 15:07:11 +01:00
|
|
|
AddSortableSpriteToDraw(wdts->image + base + ((wdts->image < 24) ? locks_base : 0), palette,
|
2007-01-14 19:57:49 +00:00
|
|
|
ti->x + wdts->delta_x, ti->y + wdts->delta_y,
|
|
|
|
wdts->width, wdts->height,
|
2007-07-26 15:07:11 +01:00
|
|
|
wdts->unk, ti->z + wdts->delta_z,
|
2007-11-10 01:17:15 +00:00
|
|
|
IsTransparencySet(TO_BUILDINGS));
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-19 17:00:54 +00:00
|
|
|
static void DrawRiverWater(const TileInfo *ti)
|
|
|
|
{
|
|
|
|
SpriteID image = SPR_FLAT_WATER_TILE;
|
|
|
|
SpriteID edges_base = GetCanalSprite(CF_RIVER_EDGE, ti->tile);
|
|
|
|
|
|
|
|
if (ti->tileh != SLOPE_FLAT) {
|
|
|
|
image = GetCanalSprite(CF_RIVER_SLOPE, ti->tile);
|
|
|
|
if (image == 0) {
|
|
|
|
image = SPR_FLAT_WATER_TILE;
|
|
|
|
} else {
|
|
|
|
switch (ti->tileh) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case SLOPE_SE: edges_base += 12; break;
|
|
|
|
case SLOPE_NE: image += 1; edges_base += 24; break;
|
|
|
|
case SLOPE_SW: image += 2; edges_base += 36; break;
|
|
|
|
case SLOPE_NW: image += 3; edges_base += 48; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawGroundSprite(image, PAL_NONE);
|
|
|
|
|
|
|
|
/* Draw canal dikes if there are no river edges to draw. */
|
|
|
|
if (edges_base <= 48) edges_base = SPR_CANAL_DIKES_BASE;
|
|
|
|
DrawWaterEdges(edges_base, ti->tile);
|
|
|
|
}
|
|
|
|
|
2008-01-22 17:48:08 +00:00
|
|
|
void DrawShoreTile(Slope tileh)
|
|
|
|
{
|
|
|
|
/* Converts the enum Slope into an offset based on SPR_SHORE_BASE.
|
|
|
|
* This allows to calculate the proper sprite to display for this Slope */
|
|
|
|
static const byte tileh_to_shoresprite[32] = {
|
|
|
|
0, 1, 2, 3, 4, 16, 6, 7, 8, 9, 17, 11, 12, 13, 14, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 10, 15, 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(!IsHalftileSlope(tileh)); // Halftile slopes need to get handled earlier.
|
|
|
|
assert(tileh != SLOPE_FLAT); // Shore is never flat
|
|
|
|
|
|
|
|
assert((tileh != SLOPE_EW) && (tileh != SLOPE_NS)); // No suitable sprites for current flooding behaviour
|
|
|
|
|
|
|
|
DrawGroundSprite(SPR_SHORE_BASE + tileh_to_shoresprite[tileh], PAL_NONE);
|
|
|
|
}
|
|
|
|
|
2004-08-09 18:04:08 +01:00
|
|
|
static void DrawTile_Water(TileInfo *ti)
|
|
|
|
{
|
2006-03-31 19:36:13 +01:00
|
|
|
switch (GetWaterTileType(ti->tile)) {
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_CLEAR:
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(SPR_FLAT_WATER_TILE, PAL_NONE);
|
2007-10-16 20:48:58 +01:00
|
|
|
if (IsCanal(ti->tile)) DrawCanalWater(ti->tile);
|
2006-12-27 12:38:02 +00:00
|
|
|
DrawBridgeMiddle(ti);
|
2006-03-31 19:36:13 +01:00
|
|
|
break;
|
|
|
|
|
2007-12-31 04:38:11 +00:00
|
|
|
case WATER_TILE_COAST: {
|
2008-01-22 17:48:08 +00:00
|
|
|
DrawShoreTile(ti->tileh);
|
2006-12-27 12:38:02 +00:00
|
|
|
DrawBridgeMiddle(ti);
|
2007-12-31 04:38:11 +00:00
|
|
|
} break;
|
2006-03-31 19:36:13 +01:00
|
|
|
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_LOCK: {
|
2006-04-03 11:50:54 +01:00
|
|
|
const WaterDrawTileStruct *t = _shiplift_display_seq[GetSection(ti->tile)];
|
2006-03-31 19:36:13 +01:00
|
|
|
DrawWaterStuff(ti, t, 0, ti->z > t[3].delta_y ? 24 : 0);
|
|
|
|
} break;
|
|
|
|
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_DEPOT:
|
2006-04-03 11:50:54 +01:00
|
|
|
DrawWaterStuff(ti, _shipdepot_display_seq[GetSection(ti->tile)], PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), 0);
|
2006-03-31 19:36:13 +01:00
|
|
|
break;
|
2008-01-19 17:00:54 +00:00
|
|
|
|
|
|
|
case WATER_TILE_RIVER:
|
|
|
|
DrawRiverWater(ti);
|
|
|
|
DrawBridgeMiddle(ti);
|
|
|
|
break;
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawShipDepotSprite(int x, int y, int image)
|
|
|
|
{
|
2005-02-22 18:27:57 +00:00
|
|
|
const WaterDrawTileStruct *wdts = _shipdepot_display_seq[image];
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawSprite(wdts++->image, PAL_NONE, x, y);
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2005-02-22 18:27:57 +00:00
|
|
|
for (; wdts->delta_x != 0x80; wdts++) {
|
2004-08-09 18:04:08 +01:00
|
|
|
Point pt = RemapCoords(wdts->delta_x, wdts->delta_y, wdts->delta_z);
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawSprite(wdts->image, PLAYER_SPRITE_COLOR(_local_player), x + pt.x, y + pt.y);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-06 17:32:49 +01:00
|
|
|
static uint GetSlopeZ_Water(TileIndex tile, uint x, uint y)
|
2004-09-10 20:02:27 +01:00
|
|
|
{
|
2006-08-06 17:32:49 +01:00
|
|
|
uint z;
|
2007-01-10 18:56:51 +00:00
|
|
|
Slope tileh = GetTileSlope(tile, &z);
|
2006-08-06 17:32:49 +01:00
|
|
|
|
|
|
|
return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2007-07-26 17:51:10 +01:00
|
|
|
static Foundation GetFoundation_Water(TileIndex tile, Slope tileh)
|
2004-09-10 20:02:27 +01:00
|
|
|
{
|
2007-07-26 17:51:10 +01:00
|
|
|
return FOUNDATION_NONE;
|
2004-08-13 19:27:33 +01:00
|
|
|
}
|
|
|
|
|
2005-06-24 13:38:35 +01:00
|
|
|
static void GetAcceptedCargo_Water(TileIndex tile, AcceptedCargo ac)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
|
|
|
/* not used */
|
|
|
|
}
|
|
|
|
|
2005-06-24 13:38:35 +01:00
|
|
|
static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2006-03-31 19:36:13 +01:00
|
|
|
switch (GetWaterTileType(tile)) {
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_CLEAR:
|
2008-01-19 17:00:54 +00:00
|
|
|
case WATER_TILE_RIVER:
|
2007-10-16 20:48:58 +01:00
|
|
|
if (!IsCanal(tile)) {
|
2006-03-31 19:36:13 +01:00
|
|
|
td->str = STR_3804_WATER;
|
|
|
|
} else {
|
|
|
|
td->str = STR_LANDINFO_CANAL;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_COAST: td->str = STR_3805_COAST_OR_RIVERBANK; break;
|
|
|
|
case WATER_TILE_LOCK : td->str = STR_LANDINFO_LOCK; break;
|
|
|
|
case WATER_TILE_DEPOT: td->str = STR_3806_SHIP_DEPOT; break;
|
2006-03-31 19:36:13 +01:00
|
|
|
default: assert(0); break;
|
2006-02-01 06:32:03 +00:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2005-06-04 12:56:32 +01:00
|
|
|
td->owner = GetTileOwner(tile);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2005-06-24 13:38:35 +01:00
|
|
|
static void AnimateTile_Water(TileIndex tile)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
|
|
|
/* not used */
|
|
|
|
}
|
|
|
|
|
2007-12-08 21:57:24 +00:00
|
|
|
/**
|
|
|
|
* Marks tile dirty if it is a canal tile.
|
|
|
|
* Called to avoid glitches when flooding tiles next to canal tile.
|
|
|
|
*
|
|
|
|
* @param tile tile to check
|
|
|
|
*/
|
2008-01-17 16:55:13 +00:00
|
|
|
static inline void MarkTileDirtyIfCanal(TileIndex tile)
|
|
|
|
{
|
2007-12-08 21:57:24 +00:00
|
|
|
if (IsTileType(tile, MP_WATER) && IsCanal(tile)) MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-02-05 14:00:32 +00:00
|
|
|
/**
|
|
|
|
* Finds a vehicle to flood.
|
|
|
|
* It does not find vehicles that are already crashed on bridges, i.e. flooded.
|
|
|
|
* @param tile the tile where to find a vehicle to flood
|
|
|
|
* @return a vehicle too flood or NULL when there is no vehicle too flood.
|
|
|
|
*/
|
|
|
|
static Vehicle *FindFloodableVehicleOnTile(TileIndex tile)
|
|
|
|
{
|
2007-06-14 09:39:27 +01:00
|
|
|
if (IsTileType(tile, MP_STATION) && IsAirport(tile)) {
|
|
|
|
const Station *st = GetStationByTile(tile);
|
|
|
|
const AirportFTAClass *airport = st->Airport();
|
|
|
|
for (uint x = 0; x < airport->size_x; x++) {
|
|
|
|
for (uint y = 0; y < airport->size_y; y++) {
|
|
|
|
tile = TILE_ADDXY(st->airport_tile, x, y);
|
|
|
|
Vehicle *v = FindVehicleOnTileZ(tile, 1 + airport->delta_z);
|
|
|
|
if (v != NULL && (v->vehstatus & VS_CRASHED) == 0) return v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No vehicle could be flooded on this airport anymore */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-05 00:16:20 +00:00
|
|
|
/* if non-uniform stations are disabled, flood some train in this train station (if there is any) */
|
|
|
|
if (!_patches.nonuniform_stations && IsTileType(tile, MP_STATION) && GetStationType(tile) == STATION_RAIL) {
|
|
|
|
const Station *st = GetStationByTile(tile);
|
|
|
|
|
|
|
|
BEGIN_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile)
|
|
|
|
if (st->TileBelongsToRailStation(t)) {
|
|
|
|
Vehicle *v = FindVehicleOnTileZ(t, 0);
|
|
|
|
if (v != NULL && (v->vehstatus & VS_CRASHED) == 0) return v;
|
|
|
|
}
|
|
|
|
END_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile)
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-02-05 14:00:32 +00:00
|
|
|
if (!IsBridgeTile(tile)) return FindVehicleOnTileZ(tile, 0);
|
|
|
|
|
|
|
|
TileIndex end = GetOtherBridgeEnd(tile);
|
|
|
|
byte z = GetBridgeHeight(tile);
|
|
|
|
Vehicle *v;
|
|
|
|
|
|
|
|
/* check the start tile first since as this is closest to the water */
|
|
|
|
v = FindVehicleOnTileZ(tile, z);
|
|
|
|
if (v != NULL && (v->vehstatus & VS_CRASHED) == 0) return v;
|
|
|
|
|
|
|
|
/* check a vehicle in between both bridge heads */
|
|
|
|
v = FindVehicleBetween(tile, end, z, true);
|
|
|
|
if (v != NULL) return v;
|
|
|
|
|
|
|
|
/* check the end tile last to give fleeing vehicles a chance to escape */
|
|
|
|
v = FindVehicleOnTileZ(end, z);
|
|
|
|
return (v != NULL && (v->vehstatus & VS_CRASHED) == 0) ? v : NULL;
|
|
|
|
}
|
|
|
|
|
2004-09-03 18:57:27 +01:00
|
|
|
static void FloodVehicle(Vehicle *v)
|
|
|
|
{
|
|
|
|
if (!(v->vehstatus & VS_CRASHED)) {
|
2004-09-06 22:20:01 +01:00
|
|
|
uint16 pass = 0;
|
2004-09-03 18:57:27 +01:00
|
|
|
|
2007-06-14 09:39:27 +01:00
|
|
|
if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_AIRCRAFT) {
|
|
|
|
if (v->type == VEH_AIRCRAFT) {
|
|
|
|
/* Crashing aircraft are always at z_pos == 1, never on z_pos == 0,
|
|
|
|
* because that's always the shadow. Except for the heliport, because
|
|
|
|
* that station has a big z_offset for the aircraft. */
|
|
|
|
if (!IsTileType(v->tile, MP_STATION) || !IsAirport(v->tile) || GetTileMaxZ(v->tile) != 0) return;
|
|
|
|
const Station *st = GetStationByTile(v->tile);
|
|
|
|
const AirportFTAClass *airport = st->Airport();
|
|
|
|
|
|
|
|
if (v->z_pos != airport->delta_z + 1) return;
|
|
|
|
}
|
2006-07-26 04:33:12 +01:00
|
|
|
Vehicle *u;
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2007-08-30 22:11:12 +01:00
|
|
|
if (v->type != VEH_AIRCRAFT) v = v->First();
|
2004-09-03 18:57:27 +01:00
|
|
|
u = v;
|
|
|
|
|
2007-06-11 15:00:16 +01:00
|
|
|
/* crash all wagons, and count passengers */
|
2004-09-03 18:57:27 +01:00
|
|
|
BEGIN_ENUM_WAGONS(v)
|
2007-06-22 12:58:59 +01:00
|
|
|
if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.Count();
|
2004-09-03 18:57:27 +01:00
|
|
|
v->vehstatus |= VS_CRASHED;
|
2008-01-16 21:17:31 +00:00
|
|
|
MarkSingleVehicleDirty(v);
|
2004-09-03 18:57:27 +01:00
|
|
|
END_ENUM_WAGONS(v)
|
|
|
|
|
|
|
|
v = u;
|
2007-06-11 15:00:16 +01:00
|
|
|
|
2007-06-14 09:39:27 +01:00
|
|
|
switch (v->type) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case VEH_TRAIN:
|
|
|
|
if (IsFrontEngine(v)) pass += 4; // driver
|
|
|
|
v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_ROAD:
|
|
|
|
if (IsRoadVehFront(v)) pass += 1; // driver
|
|
|
|
v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_AIRCRAFT:
|
|
|
|
pass += 2; // driver
|
|
|
|
v->u.air.crashed_counter = 9000; // max 10000, disappear pretty fast
|
|
|
|
break;
|
2007-06-11 15:00:16 +01:00
|
|
|
}
|
|
|
|
|
2004-12-10 18:16:08 +00:00
|
|
|
RebuildVehicleLists();
|
2005-10-23 14:04:44 +01:00
|
|
|
} else {
|
2004-09-06 22:20:01 +01:00
|
|
|
return;
|
2005-10-23 14:04:44 +01:00
|
|
|
}
|
2004-09-03 18:57:27 +01:00
|
|
|
|
2008-01-18 13:02:47 +00:00
|
|
|
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
|
2004-09-03 18:57:27 +01:00
|
|
|
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, pass);
|
2004-09-03 18:57:27 +01:00
|
|
|
AddNewsItem(STR_B006_FLOOD_VEHICLE_DESTROYED,
|
2007-04-18 23:10:36 +01:00
|
|
|
NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_VEHICLE, NT_ACCIDENT, 0),
|
2004-09-03 18:57:27 +01:00
|
|
|
v->index,
|
|
|
|
0);
|
2005-10-23 14:04:44 +01:00
|
|
|
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
|
|
|
|
SndPlayVehicleFx(SND_12_EXPLOSION, v);
|
2004-12-19 09:33:02 +00:00
|
|
|
}
|
2004-09-03 18:57:27 +01:00
|
|
|
}
|
|
|
|
|
2007-10-15 01:06:59 +01:00
|
|
|
/**
|
2008-01-22 17:48:08 +00:00
|
|
|
* Returns the behaviour of a tile during flooding.
|
2007-10-15 01:06:59 +01:00
|
|
|
*
|
2008-01-22 17:48:08 +00:00
|
|
|
* @return Behaviour of the tile
|
2007-10-15 01:06:59 +01:00
|
|
|
*/
|
2008-01-22 17:48:08 +00:00
|
|
|
static FloodingBehaviour GetFloodingBehaviour(TileIndex tile)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2008-01-22 17:48:08 +00:00
|
|
|
/* FLOOD_ACTIVE: 'single-corner-raised'-coast, sea, sea-shipdepots, sea-buoys, rail with flooded halftile
|
|
|
|
* FLOOD_DRYUP: coast with more than one corner raised
|
|
|
|
* FLOOD_PASSIVE: oilrig, dock, water-industries
|
|
|
|
* FLOOD_NONE: canals, rivers, everything else
|
|
|
|
*/
|
|
|
|
switch (GetTileType(tile)) {
|
|
|
|
case MP_WATER:
|
|
|
|
if (IsCoast(tile)) {
|
|
|
|
Slope tileh = GetTileSlope(tile, NULL);
|
|
|
|
return (HasBit(_active_water_slopes, tileh) ? FLOOD_ACTIVE : FLOOD_DRYUP);
|
|
|
|
} else {
|
|
|
|
return ((IsSea(tile) || (IsShipDepot(tile) && (GetShipDepotWaterOwner(tile) == OWNER_WATER))) ? FLOOD_ACTIVE : FLOOD_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
case MP_RAILWAY:
|
|
|
|
return ((GetRailGroundType(tile) == RAIL_GROUND_WATER) ? FLOOD_ACTIVE : FLOOD_NONE);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-01-22 17:48:08 +00:00
|
|
|
case MP_STATION:
|
|
|
|
if (IsSeaBuoyTile(tile)) return FLOOD_ACTIVE;
|
|
|
|
if (IsOilRig(tile) || IsDock(tile)) return FLOOD_PASSIVE;
|
|
|
|
return FLOOD_NONE;
|
2006-06-28 18:33:04 +01:00
|
|
|
|
2008-01-22 17:48:08 +00:00
|
|
|
case MP_INDUSTRY:
|
|
|
|
return ((GetIndustrySpec(GetIndustryType(tile))->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0 ? FLOOD_PASSIVE : FLOOD_NONE);
|
2006-02-06 09:18:04 +00:00
|
|
|
|
2008-01-22 17:48:08 +00:00
|
|
|
default:
|
|
|
|
return FLOOD_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Floods a tile.
|
|
|
|
*/
|
|
|
|
static void DoFloodTile(TileIndex target)
|
|
|
|
{
|
|
|
|
if (IsTileType(target, MP_WATER)) return;
|
|
|
|
|
|
|
|
bool flooded = false; // Will be set to true if something is changed.
|
|
|
|
|
|
|
|
_current_player = OWNER_WATER;
|
|
|
|
|
|
|
|
if (GetTileSlope(target, NULL) != SLOPE_FLAT) {
|
|
|
|
/* make coast.. */
|
|
|
|
switch (GetTileType(target)) {
|
|
|
|
case MP_RAILWAY: {
|
|
|
|
if (!IsPlainRailTile(target)) break;
|
|
|
|
|
|
|
|
flooded = FloodHalftile(target);
|
|
|
|
|
|
|
|
Vehicle *v = FindFloodableVehicleOnTile(target);
|
|
|
|
if (v != NULL) FloodVehicle(v);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MP_CLEAR:
|
|
|
|
case MP_TREES:
|
|
|
|
if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
|
|
|
|
MakeShore(target);
|
|
|
|
MarkTileDirtyByTile(target);
|
|
|
|
flooded = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Flood vehicles */
|
|
|
|
Vehicle *v = FindFloodableVehicleOnTile(target);
|
|
|
|
if (v != NULL) FloodVehicle(v);
|
|
|
|
|
|
|
|
/* flood flat tile */
|
|
|
|
if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
|
|
|
|
MakeWater(target);
|
|
|
|
MarkTileDirtyByTile(target);
|
|
|
|
flooded = true;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
2007-10-15 01:06:59 +01:00
|
|
|
|
2008-01-22 17:48:08 +00:00
|
|
|
if (flooded) {
|
|
|
|
/* Mark surrounding canal tiles dirty too to avoid glitches */
|
|
|
|
for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
|
|
|
|
MarkTileDirtyIfCanal(target + TileOffsByDir(dir));
|
|
|
|
}
|
2004-08-13 20:52:45 +01:00
|
|
|
|
2008-01-22 17:48:08 +00:00
|
|
|
/* update signals if needed */
|
|
|
|
UpdateSignalsInBuffer();
|
2006-02-01 06:32:03 +00:00
|
|
|
}
|
2004-08-13 20:52:45 +01:00
|
|
|
|
2008-01-22 17:48:08 +00:00
|
|
|
_current_player = OWNER_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drys a tile up.
|
|
|
|
*/
|
|
|
|
static void DoDryUp(TileIndex tile)
|
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_WATER) && IsCoast(tile));
|
|
|
|
_current_player = OWNER_WATER;
|
|
|
|
|
|
|
|
if (CmdSucceeded(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
|
|
|
|
MakeClear(tile, CLEAR_GRASS, 3);
|
|
|
|
MarkTileDirtyByTile(tile);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-13 20:52:45 +01:00
|
|
|
|
2008-01-22 17:48:08 +00:00
|
|
|
_current_player = OWNER_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Let a water tile floods its diagonal adjoining tiles
|
|
|
|
* called from tunnelbridge_cmd, and by TileLoop_Industry() and TileLoop_Track()
|
|
|
|
*
|
|
|
|
* @param tile the water/shore tile that floods
|
|
|
|
*/
|
|
|
|
void TileLoop_Water(TileIndex tile)
|
|
|
|
{
|
|
|
|
switch (GetFloodingBehaviour(tile)) {
|
|
|
|
case FLOOD_ACTIVE:
|
|
|
|
for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
|
|
|
|
TileIndex dest = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(dir));
|
|
|
|
if (dest == INVALID_TILE) continue;
|
|
|
|
|
|
|
|
uint z_dest;
|
|
|
|
Slope slope_dest = (Slope)(GetFoundationSlope(dest, &z_dest) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP);
|
|
|
|
if (z_dest > 0) continue;
|
|
|
|
|
|
|
|
if (!HasBit(_flood_from_dirs[slope_dest], ReverseDir(dir))) continue;
|
|
|
|
|
|
|
|
DoFloodTile(dest);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FLOOD_DRYUP: {
|
|
|
|
Slope slope_here = (Slope)(GetFoundationSlope(tile, NULL) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP);
|
|
|
|
uint check_dirs = _flood_from_dirs[slope_here];
|
|
|
|
uint dir;
|
|
|
|
FOR_EACH_SET_BIT(dir, check_dirs) {
|
|
|
|
TileIndex dest = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir((Direction)dir));
|
|
|
|
if (dest == INVALID_TILE) continue;
|
|
|
|
|
|
|
|
FloodingBehaviour dest_behaviour = GetFloodingBehaviour(dest);
|
|
|
|
if ((dest_behaviour == FLOOD_ACTIVE) || (dest_behaviour == FLOOD_PASSIVE)) return;
|
|
|
|
}
|
|
|
|
DoDryUp(tile);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: return;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2008-01-22 17:48:08 +00:00
|
|
|
}
|
2004-08-13 20:52:45 +01:00
|
|
|
|
2008-01-22 17:48:08 +00:00
|
|
|
void ConvertGroundTilesIntoWaterTiles()
|
|
|
|
{
|
|
|
|
TileIndex tile;
|
|
|
|
uint z;
|
|
|
|
Slope slope;
|
|
|
|
|
|
|
|
for (tile = 0; tile < MapSize(); ++tile) {
|
|
|
|
slope = GetTileSlope(tile, &z);
|
|
|
|
if (IsTileType(tile, MP_CLEAR) && z == 0) {
|
|
|
|
/* Make both water for tiles at level 0
|
|
|
|
* and make shore, as that looks much better
|
|
|
|
* during the generation. */
|
|
|
|
switch (slope) {
|
|
|
|
case SLOPE_FLAT:
|
|
|
|
MakeWater(tile);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SLOPE_N:
|
|
|
|
case SLOPE_E:
|
|
|
|
case SLOPE_S:
|
|
|
|
case SLOPE_W:
|
|
|
|
MakeShore(tile);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
uint check_dirs = _flood_from_dirs[slope & ~SLOPE_STEEP];
|
|
|
|
uint dir;
|
|
|
|
FOR_EACH_SET_BIT(dir, check_dirs) {
|
|
|
|
TileIndex dest = TILE_ADD(tile, TileOffsByDir((Direction)dir));
|
|
|
|
Slope slope_dest = (Slope)(GetTileSlope(dest, NULL) & ~SLOPE_STEEP);
|
|
|
|
if (HasBit(_active_water_slopes, slope_dest)) {
|
|
|
|
MakeShore(tile);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2007-05-24 23:41:50 +01:00
|
|
|
static uint32 GetTileTrackStatus_Water(TileIndex tile, TransportType mode, uint sub_mode)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2006-04-03 11:28:16 +01:00
|
|
|
static const byte coast_tracks[] = {0, 32, 4, 0, 16, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0};
|
2006-07-25 19:32:34 +01:00
|
|
|
|
|
|
|
TrackBits ts;
|
|
|
|
|
2006-02-01 06:32:03 +00:00
|
|
|
if (mode != TRANSPORT_WATER) return 0;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2006-04-03 11:28:16 +01:00
|
|
|
switch (GetWaterTileType(tile)) {
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_CLEAR: ts = TRACK_BIT_ALL; break;
|
|
|
|
case WATER_TILE_COAST: ts = (TrackBits)coast_tracks[GetTileSlope(tile, NULL) & 0xF]; break;
|
|
|
|
case WATER_TILE_LOCK: ts = AxisToTrackBits(DiagDirToAxis(GetLockDirection(tile))); break;
|
|
|
|
case WATER_TILE_DEPOT: ts = AxisToTrackBits(GetShipDepotAxis(tile)); break;
|
2008-01-19 17:00:54 +00:00
|
|
|
case WATER_TILE_RIVER: ts = (GetTileSlope(tile, NULL) == SLOPE_FLAT) ? TRACK_BIT_ALL : TRACK_BIT_NONE; break;
|
2006-04-03 11:28:16 +01:00
|
|
|
default: return 0;
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
2006-05-27 17:12:16 +01:00
|
|
|
if (TileX(tile) == 0) {
|
2007-04-06 05:10:19 +01:00
|
|
|
/* NE border: remove tracks that connects NE tile edge */
|
2006-05-27 17:12:16 +01:00
|
|
|
ts &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT);
|
|
|
|
}
|
|
|
|
if (TileY(tile) == 0) {
|
2007-04-06 05:10:19 +01:00
|
|
|
/* NW border: remove tracks that connects NW tile edge */
|
2006-05-27 17:12:16 +01:00
|
|
|
ts &= ~(TRACK_BIT_Y | TRACK_BIT_LEFT | TRACK_BIT_UPPER);
|
|
|
|
}
|
|
|
|
return ts * 0x101;
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2005-06-24 13:38:35 +01:00
|
|
|
static void ClickTile_Water(TileIndex tile)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2007-03-01 13:27:51 +00:00
|
|
|
if (GetWaterTileType(tile) == WATER_TILE_DEPOT) {
|
2006-04-03 11:28:16 +01:00
|
|
|
TileIndex tile2 = GetOtherShipDepotTile(tile);
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2007-03-08 16:27:54 +00:00
|
|
|
ShowDepotWindow(tile < tile2 ? tile : tile2, VEH_SHIP);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-18 21:56:44 +01:00
|
|
|
static void ChangeTileOwner_Water(TileIndex tile, PlayerID old_player, PlayerID new_player)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2005-06-04 12:56:32 +01:00
|
|
|
if (!IsTileOwner(tile, old_player)) return;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2006-10-14 16:49:43 +01:00
|
|
|
if (new_player != PLAYER_SPECTATOR) {
|
2005-06-04 13:13:24 +01:00
|
|
|
SetTileOwner(tile, new_player);
|
2007-07-16 22:00:40 +01:00
|
|
|
} else if (IsShipDepot(tile)) {
|
2006-04-10 08:15:58 +01:00
|
|
|
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
2007-07-16 22:00:40 +01:00
|
|
|
} else {
|
|
|
|
SetTileOwner(tile, OWNER_NONE);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-21 22:50:51 +00:00
|
|
|
static VehicleEnterTileStatus VehicleEnter_Water(Vehicle *v, TileIndex tile, int x, int y)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_CONTINUE;
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2007-08-30 18:17:04 +01:00
|
|
|
static CommandCost TerraformTile_Water(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
|
|
|
|
{
|
|
|
|
/* Canals can't be terraformed */
|
2007-10-16 20:48:58 +01:00
|
|
|
if (IsWaterTile(tile) && IsCanal(tile)) return_cmd_error(STR_MUST_DEMOLISH_CANAL_FIRST);
|
2007-08-30 18:17:04 +01:00
|
|
|
|
|
|
|
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
|
}
|
|
|
|
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
extern const TileTypeProcs _tile_type_water_procs = {
|
2006-08-22 15:38:37 +01:00
|
|
|
DrawTile_Water, /* draw_tile_proc */
|
|
|
|
GetSlopeZ_Water, /* get_slope_z_proc */
|
|
|
|
ClearTile_Water, /* clear_tile_proc */
|
|
|
|
GetAcceptedCargo_Water, /* get_accepted_cargo_proc */
|
|
|
|
GetTileDesc_Water, /* get_tile_desc_proc */
|
|
|
|
GetTileTrackStatus_Water, /* get_tile_track_status_proc */
|
|
|
|
ClickTile_Water, /* click_tile_proc */
|
|
|
|
AnimateTile_Water, /* animate_tile_proc */
|
|
|
|
TileLoop_Water, /* tile_loop_clear */
|
|
|
|
ChangeTileOwner_Water, /* change_tile_owner_clear */
|
|
|
|
NULL, /* get_produced_cargo_proc */
|
|
|
|
VehicleEnter_Water, /* vehicle_enter_tile_proc */
|
2007-07-26 17:51:10 +01:00
|
|
|
GetFoundation_Water, /* get_foundation_proc */
|
2007-08-30 18:17:04 +01:00
|
|
|
TerraformTile_Water, /* terraform_tile_proc */
|
2004-08-09 18:04:08 +01:00
|
|
|
};
|