2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file water_cmd.cpp Handling of water tiles. */
|
2007-04-06 04:10:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2007-02-24 09:42:39 +00:00
|
|
|
#include "cmd_helper.h"
|
2007-04-12 13:07:15 +00: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 17:04:08 +00:00
|
|
|
#include "town.h"
|
2008-03-28 08:53:36 +00:00
|
|
|
#include "news_func.h"
|
2008-04-17 19:10:30 +00:00
|
|
|
#include "depot_base.h"
|
|
|
|
#include "depot_func.h"
|
2007-12-19 23:26:02 +00:00
|
|
|
#include "water.h"
|
2009-10-04 17:16:41 +00:00
|
|
|
#include "industry_map.h"
|
2007-05-06 18:14:33 +00:00
|
|
|
#include "newgrf_canal.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_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-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
2008-01-22 17:48:08 +00:00
|
|
|
#include "clear_map.h"
|
2008-01-31 17:54:13 +00:00
|
|
|
#include "tree_map.h"
|
2008-09-07 11:23:10 +00:00
|
|
|
#include "aircraft.h"
|
2008-04-20 11:12:07 +00:00
|
|
|
#include "effectvehicle_func.h"
|
2008-06-11 13:54:01 +00:00
|
|
|
#include "tunnelbridge_map.h"
|
2009-06-24 17:39:54 +00:00
|
|
|
#include "station_base.h"
|
2009-02-05 17:48:08 +00:00
|
|
|
#include "ai/ai.hpp"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "core/random_func.hpp"
|
2010-05-31 20:22:57 +00:00
|
|
|
#include "core/backup_type.hpp"
|
2010-06-20 19:13:02 +00:00
|
|
|
#include "date_func.h"
|
2004-09-03 17:57:27 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
2005-08-01 16:31:19 +00:00
|
|
|
|
2008-01-22 17:48:08 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
};
|
|
|
|
|
2008-01-29 14:17:13 +00:00
|
|
|
/**
|
|
|
|
* Marks tile dirty if it is a canal or river tile.
|
|
|
|
* Called to avoid glitches when flooding tiles next to canal tile.
|
|
|
|
*
|
|
|
|
* @param tile tile to check
|
|
|
|
*/
|
|
|
|
static inline void MarkTileDirtyIfCanalOrRiver(TileIndex tile)
|
|
|
|
{
|
|
|
|
if (IsTileType(tile, MP_WATER) && (IsCanal(tile) || IsRiver(tile))) MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks the tiles around a tile as dirty, if they are canals or rivers.
|
|
|
|
*
|
|
|
|
* @param tile The center of the tile where all other tiles are marked as dirty
|
|
|
|
* @ingroup dirty
|
|
|
|
*/
|
|
|
|
static void MarkCanalsAndRiversAroundDirty(TileIndex tile)
|
|
|
|
{
|
|
|
|
for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
|
|
|
|
MarkTileDirtyIfCanalOrRiver(tile + TileOffsByDir(dir));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-24 08:45:04 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Build a ship depot.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile where ship depot is built
|
2007-04-06 04:10:19 +00:00
|
|
|
* @param flags type of operation
|
2007-02-24 09:42:39 +00:00
|
|
|
* @param p1 bit 0 depot orientation (Axis)
|
2005-05-09 22:33:00 +00:00
|
|
|
* @param p2 unused
|
2009-09-18 14:23:58 +00:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-04-13 17:29:19 +00:00
|
|
|
Axis axis = Extract<Axis, 0, 1>(p1);
|
2007-02-24 09:42:39 +00:00
|
|
|
|
2010-03-14 13:49:23 +00:00
|
|
|
TileIndex tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-11-21 18:38:45 +00:00
|
|
|
if (!HasTileWaterGround(tile) || !HasTileWaterGround(tile2)) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_MUST_BE_BUILT_ON_WATER);
|
2008-02-02 09:28:43 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-09-07 19:20:15 +00:00
|
|
|
if ((MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) ||
|
|
|
|
(MayHaveBridgeAbove(tile2) && IsBridgeAbove(tile2))) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2008-02-02 09:28:43 +00:00
|
|
|
if (GetTileSlope(tile, NULL) != SLOPE_FLAT || GetTileSlope(tile2, NULL) != SLOPE_FLAT) {
|
|
|
|
/* Prevent depots on rapids */
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
|
2008-02-02 09:28:43 +00:00
|
|
|
}
|
|
|
|
|
2010-09-05 16:33:32 +00:00
|
|
|
if (!Depot::CanAllocateItem()) return CMD_ERROR;
|
|
|
|
|
2008-02-02 09:28:43 +00:00
|
|
|
WaterClass wc1 = GetWaterClass(tile);
|
|
|
|
WaterClass wc2 = GetWaterClass(tile2);
|
2010-09-05 16:33:32 +00:00
|
|
|
CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_DEPOT_SHIP]);
|
|
|
|
|
|
|
|
bool add_cost = !IsWaterTile(tile);
|
|
|
|
CommandCost ret = DoCommand(tile, 0, 0, flags | DC_AUTO, CMD_LANDSCAPE_CLEAR);
|
2010-03-14 12:58:51 +00:00
|
|
|
if (ret.Failed()) return ret;
|
2010-09-05 16:33:32 +00:00
|
|
|
if (add_cost) {
|
|
|
|
cost.AddCost(ret);
|
|
|
|
}
|
|
|
|
add_cost = !IsWaterTile(tile2);
|
|
|
|
ret = DoCommand(tile2, 0, 0, flags | DC_AUTO, CMD_LANDSCAPE_CLEAR);
|
2010-03-14 12:58:51 +00:00
|
|
|
if (ret.Failed()) return ret;
|
2010-09-05 16:33:32 +00:00
|
|
|
if (add_cost) {
|
|
|
|
cost.AddCost(ret);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2008-04-23 20:56:08 +00:00
|
|
|
Depot *depot = new Depot(tile);
|
2010-06-20 19:13:02 +00:00
|
|
|
depot->build_date = _date;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-09-10 14:33:07 +00:00
|
|
|
MakeShipDepot(tile, _current_company, depot->index, DEPOT_NORTH, axis, wc1);
|
|
|
|
MakeShipDepot(tile2, _current_company, depot->index, DEPOT_SOUTH, axis, wc2);
|
2006-03-30 11:11:35 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
MarkTileDirtyByTile(tile2);
|
2010-05-12 19:21:00 +00:00
|
|
|
MakeDefaultName(depot);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-09-05 16:33:32 +00:00
|
|
|
return cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-02-02 09:28:43 +00:00
|
|
|
void MakeWaterKeepingClass(TileIndex tile, Owner o)
|
2007-12-07 21:14:54 +00:00
|
|
|
{
|
2008-07-26 16:14:10 +00:00
|
|
|
WaterClass wc = GetWaterClass(tile);
|
|
|
|
|
|
|
|
/* Autoslope might turn an originally canal or river tile into land */
|
|
|
|
uint z;
|
|
|
|
if (GetTileSlope(tile, &z) != SLOPE_FLAT) wc = WATER_CLASS_INVALID;
|
|
|
|
|
|
|
|
if (wc == WATER_CLASS_SEA && z > 0) wc = WATER_CLASS_CANAL;
|
2008-02-02 09:28:43 +00:00
|
|
|
|
2010-08-27 20:46:36 +00:00
|
|
|
/* Zero map array and terminate animation */
|
|
|
|
DoClearSquare(tile);
|
|
|
|
|
|
|
|
/* Maybe change to water */
|
2008-07-26 16:14:10 +00:00
|
|
|
switch (wc) {
|
2009-10-20 12:31:11 +00:00
|
|
|
case WATER_CLASS_SEA: MakeSea(tile); break;
|
2008-02-02 09:28:43 +00:00
|
|
|
case WATER_CLASS_CANAL: MakeCanal(tile, o, Random()); break;
|
|
|
|
case WATER_CLASS_RIVER: MakeRiver(tile, Random()); break;
|
2010-08-27 20:46:36 +00:00
|
|
|
default: break;
|
2007-12-07 21:14:54 +00:00
|
|
|
}
|
2010-08-27 20:46:36 +00:00
|
|
|
|
|
|
|
MarkTileDirtyByTile(tile);
|
2007-12-07 21:14:54 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 21:20:05 +00:00
|
|
|
static CommandCost RemoveShipDepot(TileIndex tile, DoCommandFlag flags)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-30 11:21:36 +00:00
|
|
|
if (!IsShipDepot(tile)) return CMD_ERROR;
|
2010-03-07 20:44:05 +00:00
|
|
|
|
|
|
|
CommandCost ret = CheckTileOwnership(tile);
|
|
|
|
if (ret.Failed()) return ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-02-09 17:30:13 +00:00
|
|
|
TileIndex tile2 = GetOtherShipDepotTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-02-09 17:30:13 +00:00
|
|
|
/* do not check for ship on tile when company goes bankrupt */
|
|
|
|
if (!(flags & DC_BANKRUPT)) {
|
2010-03-05 21:20:22 +00:00
|
|
|
CommandCost ret = EnsureNoVehicleOnGround(tile);
|
|
|
|
if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile2);
|
|
|
|
if (ret.Failed()) return ret;
|
2008-02-09 17:30:13 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2009-09-10 14:37:55 +00:00
|
|
|
delete Depot::GetByTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-02-06 15:32:06 +00:00
|
|
|
MakeWaterKeepingClass(tile, GetTileOwner(tile));
|
|
|
|
MakeWaterKeepingClass(tile2, GetTileOwner(tile2));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-11-07 22:47:54 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_SHIP]);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Builds a lock.
|
2010-04-25 13:44:49 +00:00
|
|
|
* @param tile Central tile of the lock.
|
|
|
|
* @param dir Uphill direction.
|
|
|
|
* @param flags Operation to perform.
|
|
|
|
* @return The cost in case of success, or an error code if it failed.
|
|
|
|
*/
|
2010-04-24 21:03:40 +00:00
|
|
|
static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlag flags)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-04-25 13:50:15 +00:00
|
|
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2007-04-06 04:10:19 +00:00
|
|
|
/* middle tile */
|
2010-03-14 13:49:23 +00:00
|
|
|
CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2010-03-14 12:58:51 +00:00
|
|
|
if (ret.Failed()) return ret;
|
2010-04-25 13:50:15 +00:00
|
|
|
cost.AddCost(ret);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2010-03-14 13:49:23 +00:00
|
|
|
int delta = TileOffsByDiagDir(dir);
|
2007-04-06 04:10:19 +00:00
|
|
|
/* lower tile */
|
2008-02-02 09:28:43 +00:00
|
|
|
WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WATER_CLASS_CANAL;
|
|
|
|
|
2010-04-25 13:50:15 +00:00
|
|
|
if (!IsWaterTile(tile - delta)) {
|
|
|
|
ret = DoCommand(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
|
if (ret.Failed()) return ret;
|
|
|
|
cost.AddCost(ret);
|
2011-02-06 12:16:06 +00:00
|
|
|
cost.AddCost(_price[PR_BUILD_CANAL]);
|
2010-04-25 13:50:15 +00:00
|
|
|
}
|
2006-04-23 13:48:16 +00:00
|
|
|
if (GetTileSlope(tile - delta, NULL) != SLOPE_FLAT) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
2006-04-23 13:48:16 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-06 04:10:19 +00:00
|
|
|
/* upper tile */
|
2008-02-02 09:28:43 +00:00
|
|
|
WaterClass wc_upper = IsWaterTile(tile + delta) ? GetWaterClass(tile + delta) : WATER_CLASS_CANAL;
|
|
|
|
|
2010-04-25 13:50:15 +00:00
|
|
|
if (!IsWaterTile(tile + delta)) {
|
|
|
|
ret = DoCommand(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
|
if (ret.Failed()) return ret;
|
|
|
|
cost.AddCost(ret);
|
2011-02-06 12:16:06 +00:00
|
|
|
cost.AddCost(_price[PR_BUILD_CANAL]);
|
2010-04-25 13:50:15 +00:00
|
|
|
}
|
2006-04-23 13:48:16 +00:00
|
|
|
if (GetTileSlope(tile + delta, NULL) != SLOPE_FLAT) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
2006-04-23 13:48:16 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00: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))) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2008-09-30 20:39:50 +00:00
|
|
|
MakeLock(tile, _current_company, dir, wc_lower, wc_upper);
|
2006-03-30 11:11:35 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
MarkTileDirtyByTile(tile - delta);
|
|
|
|
MarkTileDirtyByTile(tile + delta);
|
2008-01-29 14:17:13 +00:00
|
|
|
MarkCanalsAndRiversAroundDirty(tile - delta);
|
|
|
|
MarkCanalsAndRiversAroundDirty(tile + delta);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2010-04-25 13:56:51 +00:00
|
|
|
cost.AddCost(_price[PR_BUILD_LOCK]);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-04-25 13:50:15 +00:00
|
|
|
return cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Remove a lock.
|
2010-04-25 13:44:49 +00:00
|
|
|
* @param tile Central tile of the lock.
|
|
|
|
* @param flags Operation to perform.
|
|
|
|
* @return The cost in case of success, or an error code if it failed.
|
|
|
|
*/
|
2010-04-24 21:03:40 +00:00
|
|
|
static CommandCost RemoveLock(TileIndex tile, DoCommandFlag flags)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-03-07 20:44:05 +00:00
|
|
|
if (GetTileOwner(tile) != OWNER_NONE) {
|
|
|
|
CommandCost ret = CheckTileOwnership(tile);
|
|
|
|
if (ret.Failed()) return ret;
|
|
|
|
}
|
2006-06-03 15:10:39 +00:00
|
|
|
|
2010-03-14 13:49:23 +00:00
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile));
|
|
|
|
|
2007-04-06 04:10:19 +00:00
|
|
|
/* make sure no vehicle is on the tile. */
|
2010-03-07 22:31:18 +00:00
|
|
|
CommandCost ret = EnsureNoVehicleOnGround(tile);
|
2010-03-05 21:20:22 +00:00
|
|
|
if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile + delta);
|
|
|
|
if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta);
|
|
|
|
if (ret.Failed()) return ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
DoClearSquare(tile);
|
2008-02-02 09:28:43 +00:00
|
|
|
MakeWaterKeepingClass(tile + delta, GetTileOwner(tile));
|
|
|
|
MakeWaterKeepingClass(tile - delta, GetTileOwner(tile));
|
2008-01-29 14:17:13 +00:00
|
|
|
MarkCanalsAndRiversAroundDirty(tile - delta);
|
|
|
|
MarkCanalsAndRiversAroundDirty(tile + delta);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2010-04-25 13:56:51 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_LOCK]);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Builds a lock.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile where to place the lock
|
2007-04-06 04:10:19 +00:00
|
|
|
* @param flags type of operation
|
2005-05-12 23:46:01 +00:00
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 unused
|
2009-09-18 14:23:58 +00:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2005-05-12 23:46:01 +00:00
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost CmdBuildLock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-01-25 15:47:58 +00:00
|
|
|
DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile, NULL));
|
2009-04-21 23:40:56 +00:00
|
|
|
if (dir == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
2008-01-23 08:47:49 +00:00
|
|
|
|
|
|
|
/* Disallow building of locks on river rapids */
|
2009-04-21 23:40:56 +00:00
|
|
|
if (IsWaterTile(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
|
2008-01-23 08:47:49 +00:00
|
|
|
|
2010-04-24 21:03:40 +00:00
|
|
|
return DoBuildLock(tile, dir, flags);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Build a piece of canal.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile end tile of stretch-dragging
|
2007-04-06 04:10:19 +00:00
|
|
|
* @param flags type of operation
|
2005-05-12 23:46:01 +00:00
|
|
|
* @param p1 start tile of stretch-dragging
|
2010-04-17 23:34:00 +00:00
|
|
|
* @param p2 waterclass to build. sea and river can only be built in scenario editor
|
2009-09-18 14:23:58 +00:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2005-05-12 23:46:01 +00:00
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-04-17 23:34:00 +00:00
|
|
|
WaterClass wc = Extract<WaterClass, 0, 2>(p2);
|
|
|
|
if (p1 >= MapSize() || wc == WATER_CLASS_INVALID) 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 */
|
2010-04-17 23:34:00 +00:00
|
|
|
if (wc != WATER_CLASS_CANAL && _game_mode != GM_EDITOR) return CMD_ERROR;
|
2005-05-12 23:46:01 +00:00
|
|
|
|
2010-01-04 18:37:47 +00:00
|
|
|
TileArea ta(tile, p1);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-05-12 23:46:01 +00:00
|
|
|
/* Outside the editor you can only drag canals, and not areas */
|
2010-01-04 18:37:47 +00:00
|
|
|
if (_game_mode != GM_EDITOR && ta.w != 1 && ta.h != 1) return CMD_ERROR;
|
2005-05-12 23:46:01 +00:00
|
|
|
|
2010-03-14 13:49:23 +00:00
|
|
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
2010-01-04 18:37:47 +00:00
|
|
|
TILE_AREA_LOOP(tile, ta) {
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost ret;
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2008-01-19 17:00:54 +00:00
|
|
|
Slope slope = GetTileSlope(tile, NULL);
|
2010-04-17 23:34:00 +00:00
|
|
|
if (slope != SLOPE_FLAT && (wc != WATER_CLASS_RIVER || !IsInclinedSlope(slope))) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
|
2006-04-23 13:48:16 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-06 04:10:19 +00:00
|
|
|
/* can't make water of water! */
|
2010-04-17 23:34:00 +00:00
|
|
|
if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || wc == WATER_CLASS_SEA)) continue;
|
2006-03-12 12:19:25 +00:00
|
|
|
|
2010-09-05 16:00:36 +00:00
|
|
|
ret = DoCommand(tile, 0, 0, flags | DC_FORCE_CLEAR_TILE, CMD_LANDSCAPE_CLEAR);
|
2010-01-18 22:57:21 +00:00
|
|
|
if (ret.Failed()) return ret;
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(ret);
|
2006-06-07 19:35:21 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2010-04-17 23:34:00 +00:00
|
|
|
switch (wc) {
|
|
|
|
case WATER_CLASS_RIVER:
|
|
|
|
MakeRiver(tile, Random());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WATER_CLASS_SEA:
|
|
|
|
if (TileHeight(tile) == 0) {
|
|
|
|
MakeSea(tile);
|
|
|
|
break;
|
|
|
|
}
|
2010-08-01 20:52:11 +00:00
|
|
|
/* FALL THROUGH */
|
|
|
|
|
2010-04-17 23:34:00 +00:00
|
|
|
default:
|
|
|
|
MakeCanal(tile, _current_company, Random());
|
|
|
|
break;
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
2006-03-13 12:55:20 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2008-01-29 14:17:13 +00:00
|
|
|
MarkCanalsAndRiversAroundDirty(tile);
|
2006-03-13 12:55:20 +00:00
|
|
|
}
|
2006-03-12 12:19:25 +00:00
|
|
|
|
2010-04-25 13:56:51 +00:00
|
|
|
cost.AddCost(_price[PR_BUILD_CANAL]);
|
2009-07-26 21:50:30 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
if (cost.GetCost() == 0) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
2006-03-12 12:19:25 +00:00
|
|
|
} else {
|
|
|
|
return cost;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 21:20:05 +00:00
|
|
|
static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlag flags)
|
2005-06-24 12:38:35 +00:00
|
|
|
{
|
2006-04-03 10:50:54 +00:00
|
|
|
switch (GetWaterTileType(tile)) {
|
2010-03-05 21:20:22 +00:00
|
|
|
case WATER_TILE_CLEAR: {
|
2009-04-21 23:40:56 +00:00
|
|
|
if (flags & DC_NO_WATER) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-04-25 13:56:51 +00:00
|
|
|
Money base_cost = IsCanal(tile) ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER];
|
2009-01-21 02:31:55 +00:00
|
|
|
/* Make sure freeform edges are allowed or it's not an edge tile. */
|
|
|
|
if (!_settings_game.construction.freeform_edges && (!IsInsideMM(TileX(tile), 1, MapMaxX() - 1) ||
|
|
|
|
!IsInsideMM(TileY(tile), 1, MapMaxY() - 1))) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP);
|
2006-04-03 10:50:54 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-08-31 20:03:50 +00:00
|
|
|
/* Make sure no vehicle is on the tile */
|
2010-03-05 21:20:22 +00:00
|
|
|
CommandCost ret = EnsureNoVehicleOnGround(tile);
|
|
|
|
if (ret.Failed()) return ret;
|
2007-08-31 20:03:50 +00:00
|
|
|
|
2010-03-07 20:44:05 +00:00
|
|
|
if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE) {
|
|
|
|
CommandCost ret = CheckTileOwnership(tile);
|
|
|
|
if (ret.Failed()) return ret;
|
|
|
|
}
|
2006-06-03 15:10:39 +00:00
|
|
|
|
2008-01-29 14:17:13 +00:00
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
DoClearSquare(tile);
|
|
|
|
MarkCanalsAndRiversAroundDirty(tile);
|
|
|
|
}
|
2010-04-25 13:56:51 +00:00
|
|
|
|
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, base_cost);
|
2010-03-05 21:20:22 +00:00
|
|
|
}
|
2006-04-04 06:01:45 +00:00
|
|
|
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_COAST: {
|
2006-04-23 13:48:16 +00:00
|
|
|
Slope slope = GetTileSlope(tile, NULL);
|
2006-04-04 06:01:45 +00:00
|
|
|
|
2007-04-06 04:10:19 +00:00
|
|
|
/* Make sure no vehicle is on the tile */
|
2010-03-05 21:20:22 +00:00
|
|
|
CommandCost ret = EnsureNoVehicleOnGround(tile);
|
|
|
|
if (ret.Failed()) return ret;
|
2006-04-04 06:01:45 +00:00
|
|
|
|
2008-01-29 14:17:13 +00:00
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
DoClearSquare(tile);
|
|
|
|
MarkCanalsAndRiversAroundDirty(tile);
|
|
|
|
}
|
2008-01-25 15:47:58 +00:00
|
|
|
if (IsSlopeWithOneCornerRaised(slope)) {
|
2009-11-07 22:47:54 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WATER]);
|
2006-04-04 06:01:45 +00:00
|
|
|
} else {
|
2009-11-07 22:47:54 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_ROUGH]);
|
2006-04-03 10:50:54 +00:00
|
|
|
}
|
2006-04-04 06:01:45 +00:00
|
|
|
}
|
|
|
|
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_LOCK: {
|
2010-04-24 21:03:40 +00:00
|
|
|
static const TileIndexDiffC _lock_tomiddle_offs[] = {
|
2006-04-04 06:01:45 +00:00
|
|
|
{ 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
|
|
|
|
};
|
|
|
|
|
2009-04-21 23:40:56 +00:00
|
|
|
if (flags & DC_AUTO) return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
|
2008-09-30 20:39:50 +00:00
|
|
|
if (_current_company == OWNER_WATER) return CMD_ERROR;
|
2007-04-06 04:10:19 +00:00
|
|
|
/* move to the middle tile.. */
|
2010-04-24 21:03:40 +00:00
|
|
|
return RemoveLock(tile + ToTileIndexDiff(_lock_tomiddle_offs[GetSection(tile)]), flags);
|
2006-04-04 06:01:45 +00:00
|
|
|
}
|
|
|
|
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_DEPOT:
|
2009-04-21 23:40:56 +00:00
|
|
|
if (flags & DC_AUTO) return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
|
2006-04-03 10:50:54 +00:00
|
|
|
return RemoveShipDepot(tile, flags);
|
2006-04-03 18:12:42 +00:00
|
|
|
|
2006-04-04 06:01:45 +00:00
|
|
|
default:
|
|
|
|
NOT_REACHED();
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-01-29 13:54:52 +00:00
|
|
|
/**
|
|
|
|
* return true if a tile is a water tile wrt. a certain direction.
|
|
|
|
*
|
|
|
|
* @param tile The tile of interest.
|
|
|
|
* @param from The direction of interest.
|
|
|
|
* @return true iff the tile is water in the view of 'from'.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static bool IsWateredTile(TileIndex tile, Direction from)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-29 15:12:40 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2006-06-07 19:35:21 +00:00
|
|
|
case MP_WATER:
|
2008-06-11 16:22:07 +00:00
|
|
|
switch (GetWaterTileType(tile)) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case WATER_TILE_DEPOT: case WATER_TILE_CLEAR: return true;
|
|
|
|
case WATER_TILE_LOCK: return DiagDirToAxis(GetLockDirection(tile)) == DiagDirToAxis(DirToDiagDir(from));
|
|
|
|
|
|
|
|
case WATER_TILE_COAST:
|
|
|
|
switch (GetTileSlope(tile, NULL)) {
|
|
|
|
case SLOPE_W: return (from == DIR_SE) || (from == DIR_E) || (from == DIR_NE);
|
|
|
|
case SLOPE_S: return (from == DIR_NE) || (from == DIR_N) || (from == DIR_NW);
|
|
|
|
case SLOPE_E: return (from == DIR_NW) || (from == DIR_W) || (from == DIR_SW);
|
|
|
|
case SLOPE_N: return (from == DIR_SW) || (from == DIR_S) || (from == DIR_SE);
|
|
|
|
default: return false;
|
|
|
|
}
|
2008-01-29 13:54:52 +00:00
|
|
|
}
|
2006-06-07 19:35:21 +00:00
|
|
|
|
2008-01-25 16:51:35 +00:00
|
|
|
case MP_RAILWAY:
|
|
|
|
if (GetRailGroundType(tile) == RAIL_GROUND_WATER) {
|
2009-05-18 01:26:23 +00:00
|
|
|
assert(IsPlainRail(tile));
|
2008-01-29 13:54:52 +00:00
|
|
|
switch (GetTileSlope(tile, NULL)) {
|
|
|
|
case SLOPE_W: return (from == DIR_SE) || (from == DIR_E) || (from == DIR_NE);
|
|
|
|
case SLOPE_S: return (from == DIR_NE) || (from == DIR_N) || (from == DIR_NW);
|
|
|
|
case SLOPE_E: return (from == DIR_NW) || (from == DIR_W) || (from == DIR_SW);
|
|
|
|
case SLOPE_N: return (from == DIR_SW) || (from == DIR_S) || (from == DIR_SE);
|
|
|
|
default: return false;
|
|
|
|
}
|
2008-01-25 16:51:35 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
2008-07-27 09:12:18 +00:00
|
|
|
case MP_STATION:
|
2008-07-27 09:16:23 +00:00
|
|
|
if (IsOilRig(tile)) {
|
|
|
|
/* Do not draw waterborders inside of industries.
|
|
|
|
* Note: There is no easy way to detect the industry of an oilrig tile. */
|
|
|
|
TileIndex src_tile = tile + TileOffsByDir(from);
|
|
|
|
if ((IsTileType(src_tile, MP_STATION) && IsOilRig(src_tile)) ||
|
|
|
|
(IsTileType(src_tile, MP_INDUSTRY))) return true;
|
|
|
|
|
2010-09-05 13:18:54 +00:00
|
|
|
return IsTileOnWater(tile);
|
2008-07-27 09:16:23 +00:00
|
|
|
}
|
2008-07-27 09:12:18 +00:00
|
|
|
return (IsDock(tile) && GetTileSlope(tile, NULL) == SLOPE_FLAT) || IsBuoy(tile);
|
|
|
|
|
2008-07-27 09:16:23 +00:00
|
|
|
case MP_INDUSTRY: {
|
|
|
|
/* Do not draw waterborders inside of industries.
|
|
|
|
* Note: There is no easy way to detect the industry of an oilrig tile. */
|
|
|
|
TileIndex src_tile = tile + TileOffsByDir(from);
|
|
|
|
if ((IsTileType(src_tile, MP_STATION) && IsOilRig(src_tile)) ||
|
|
|
|
(IsTileType(src_tile, MP_INDUSTRY) && GetIndustryIndex(src_tile) == GetIndustryIndex(tile))) return true;
|
|
|
|
|
2010-08-26 19:29:20 +00:00
|
|
|
return IsTileOnWater(tile);
|
2008-07-27 09:16:23 +00:00
|
|
|
}
|
|
|
|
|
2010-08-27 22:29:13 +00:00
|
|
|
case MP_OBJECT: return IsTileOnWater(tile);
|
|
|
|
|
2008-06-11 16:22:07 +00:00
|
|
|
case MP_TUNNELBRIDGE: return GetTunnelBridgeTransportType(tile) == TRANSPORT_WATER && ReverseDiagDir(GetTunnelBridgeDirection(tile)) == DirToDiagDir(from);
|
2008-07-27 09:16:23 +00:00
|
|
|
|
2007-08-31 19:46:45 +00:00
|
|
|
default: return false;
|
2005-01-17 09:41:46 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 17:48:07 +00:00
|
|
|
/**
|
|
|
|
* Draw a water sprite, potentially with a NewGRF-modified sprite offset.
|
|
|
|
* @param base Sprite base.
|
|
|
|
* @param offset Sprite offset.
|
|
|
|
* @param feature The type of sprite that is drawn.
|
|
|
|
* @param tile Tile index to draw.
|
|
|
|
*/
|
|
|
|
static void DrawWaterSprite(SpriteID base, uint offset, CanalFeature feature, TileIndex tile)
|
|
|
|
{
|
|
|
|
if (base != SPR_FLAT_WATER_TILE) {
|
|
|
|
/* Only call offset callback if the sprite is NewGRF-provided. */
|
|
|
|
offset = GetCanalSpriteOffset(feature, tile, offset);
|
|
|
|
}
|
|
|
|
DrawGroundSprite(base + offset, PAL_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw canal or river edges.
|
|
|
|
* @param canal True if canal edges should be drawn, false for river edges.
|
|
|
|
* @param offset Sprite offset.
|
|
|
|
* @param tile Tile to draw.
|
|
|
|
*/
|
|
|
|
static void DrawWaterEdges(bool canal, uint offset, TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-08-03 17:48:07 +00:00
|
|
|
CanalFeature feature;
|
|
|
|
SpriteID base = 0;
|
|
|
|
if (canal) {
|
|
|
|
feature = CF_DIKES;
|
|
|
|
base = GetCanalSprite(CF_DIKES, tile);
|
|
|
|
if (base == 0) base = SPR_CANAL_DIKES_BASE;
|
|
|
|
} else {
|
|
|
|
feature = CF_RIVER_EDGE;
|
|
|
|
base = GetCanalSprite(CF_RIVER_EDGE, tile);
|
|
|
|
if (base == 0) return; // Don't draw if no sprites provided.
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
uint wa;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-04-06 04:10:19 +00:00
|
|
|
/* determine the edges around with water. */
|
2008-01-29 13:54:52 +00:00
|
|
|
wa = IsWateredTile(TILE_ADDXY(tile, -1, 0), DIR_SW) << 0;
|
|
|
|
wa += IsWateredTile(TILE_ADDXY(tile, 0, 1), DIR_NW) << 1;
|
|
|
|
wa += IsWateredTile(TILE_ADDXY(tile, 1, 0), DIR_NE) << 2;
|
|
|
|
wa += IsWateredTile(TILE_ADDXY(tile, 0, -1), DIR_SE) << 3;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2010-08-03 17:48:07 +00:00
|
|
|
if (!(wa & 1)) DrawWaterSprite(base, offset, feature, tile);
|
|
|
|
if (!(wa & 2)) DrawWaterSprite(base, offset + 1, feature, tile);
|
|
|
|
if (!(wa & 4)) DrawWaterSprite(base, offset + 2, feature, tile);
|
|
|
|
if (!(wa & 8)) DrawWaterSprite(base, offset + 3, feature, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-06 04:10:19 +00:00
|
|
|
/* right corner */
|
2006-02-06 09:18:04 +00:00
|
|
|
switch (wa & 0x03) {
|
2010-08-03 17:48:07 +00:00
|
|
|
case 0: DrawWaterSprite(base, offset + 4, feature, tile); break;
|
|
|
|
case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1), DIR_W)) DrawWaterSprite(base, offset + 8, feature, tile); break;
|
2006-02-06 09:18:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-06 04:10:19 +00:00
|
|
|
/* bottom corner */
|
2006-02-06 09:18:04 +00:00
|
|
|
switch (wa & 0x06) {
|
2010-08-03 17:48:07 +00:00
|
|
|
case 0: DrawWaterSprite(base, offset + 5, feature, tile); break;
|
|
|
|
case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1), DIR_N)) DrawWaterSprite(base, offset + 9, feature, tile); break;
|
2006-02-06 09:18:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-06 04:10:19 +00:00
|
|
|
/* left corner */
|
2006-02-06 09:18:04 +00:00
|
|
|
switch (wa & 0x0C) {
|
2010-08-03 17:48:07 +00:00
|
|
|
case 0: DrawWaterSprite(base, offset + 6, feature, tile); break;
|
|
|
|
case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1), DIR_E)) DrawWaterSprite(base, offset + 10, feature, tile); break;
|
2006-02-06 09:18:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-06 04:10:19 +00:00
|
|
|
/* upper corner */
|
2006-02-06 09:18:04 +00:00
|
|
|
switch (wa & 0x09) {
|
2010-08-03 17:48:07 +00:00
|
|
|
case 0: DrawWaterSprite(base, offset + 7, feature, tile); break;
|
|
|
|
case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1), DIR_S)) DrawWaterSprite(base, offset + 11, feature, tile); break;
|
2006-02-06 09:18:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-02-02 09:28:43 +00:00
|
|
|
/** Draw a plain sea water tile with no edges */
|
2008-02-06 16:12:23 +00:00
|
|
|
static void DrawSeaWater(TileIndex tile)
|
2008-02-02 09:28:43 +00:00
|
|
|
{
|
|
|
|
DrawGroundSprite(SPR_FLAT_WATER_TILE, PAL_NONE);
|
|
|
|
}
|
|
|
|
|
2008-01-19 17:00:54 +00:00
|
|
|
/** draw a canal styled water tile with dikes around */
|
2008-02-06 16:12:23 +00:00
|
|
|
static void DrawCanalWater(TileIndex tile)
|
2008-01-19 17:00:54 +00:00
|
|
|
{
|
2010-08-03 17:48:03 +00:00
|
|
|
SpriteID image = SPR_FLAT_WATER_TILE;
|
|
|
|
if (HasBit(_water_feature[CF_WATERSLOPE].flags, CFF_HAS_FLAT_SPRITE)) {
|
|
|
|
/* First water slope sprite is flat water. */
|
|
|
|
image = GetCanalSprite(CF_WATERSLOPE, tile);
|
|
|
|
if (image == 0) image = SPR_FLAT_WATER_TILE;
|
|
|
|
}
|
2010-08-03 17:48:07 +00:00
|
|
|
DrawWaterSprite(image, 0, CF_WATERSLOPE, tile);
|
2008-01-19 17:00:54 +00:00
|
|
|
|
2010-08-03 17:48:07 +00:00
|
|
|
DrawWaterEdges(true, 0, tile);
|
2008-01-19 17:00:54 +00:00
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "table/water_land.h"
|
|
|
|
|
2010-08-03 17:47:43 +00:00
|
|
|
/**
|
|
|
|
* Draw a build sprite sequence for water tiles.
|
|
|
|
* If buildings are invisible, nothing will be drawn.
|
|
|
|
* @param ti Tile info.
|
|
|
|
* @param wdts Sprite sequence to draw.
|
|
|
|
* @param base Base sprite.
|
|
|
|
* @param offset Additional sprite offset.
|
|
|
|
* @param palette Palette to use.
|
|
|
|
*/
|
2010-08-03 17:48:07 +00:00
|
|
|
static void DrawWaterTileStruct(const TileInfo *ti, const WaterDrawTileStruct *wdts, SpriteID base, uint offset, PaletteID palette, CanalFeature feature)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-08-03 17:47:43 +00:00
|
|
|
/* Don't draw if buildings are invisible. */
|
2008-04-03 19:55:40 +00:00
|
|
|
if (IsInvisibilitySet(TO_BUILDINGS)) return;
|
|
|
|
|
2005-02-22 18:27:57 +00:00
|
|
|
for (; wdts->delta_x != 0x80; wdts++) {
|
2010-08-03 17:48:07 +00:00
|
|
|
uint tile_offs = offset + wdts->image;
|
|
|
|
if (feature < CF_END) tile_offs = GetCanalSpriteOffset(feature, ti->tile, tile_offs);
|
|
|
|
AddSortableSpriteToDraw(base + tile_offs, palette,
|
2007-01-14 19:57:49 +00:00
|
|
|
ti->x + wdts->delta_x, ti->y + wdts->delta_y,
|
2009-02-20 23:21:04 +00:00
|
|
|
wdts->size_x, wdts->size_y,
|
|
|
|
wdts->size_z, ti->z + wdts->delta_z,
|
2007-11-10 01:17:15 +00:00
|
|
|
IsTransparencySet(TO_BUILDINGS));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 17:47:43 +00:00
|
|
|
/** Draw a lock tile. */
|
|
|
|
static void DrawWaterLock(const TileInfo *ti)
|
|
|
|
{
|
|
|
|
const WaterDrawTileStruct *wdts = _lock_display_seq[GetSection(ti->tile)];
|
|
|
|
|
|
|
|
/* Draw ground sprite. */
|
2010-08-03 17:48:03 +00:00
|
|
|
SpriteID image = wdts++->image;
|
|
|
|
|
2010-08-03 17:47:43 +00:00
|
|
|
SpriteID water_base = GetCanalSprite(CF_WATERSLOPE, ti->tile);
|
2010-08-03 17:48:03 +00:00
|
|
|
if (water_base == 0) {
|
|
|
|
/* Use default sprites. */
|
|
|
|
water_base = SPR_CANALS_BASE;
|
|
|
|
} else if (HasBit(_water_feature[CF_WATERSLOPE].flags, CFF_HAS_FLAT_SPRITE)) {
|
|
|
|
/* NewGRF supplies a flat sprite as first sprite. */
|
|
|
|
if (image == SPR_FLAT_WATER_TILE) {
|
|
|
|
image = water_base;
|
|
|
|
} else {
|
|
|
|
image++;
|
|
|
|
}
|
|
|
|
}
|
2010-08-03 17:47:43 +00:00
|
|
|
|
2010-08-03 17:48:03 +00:00
|
|
|
if (image < 5) image += water_base;
|
2010-08-03 17:47:43 +00:00
|
|
|
DrawGroundSprite(image, PAL_NONE);
|
|
|
|
|
|
|
|
/* Draw structures. */
|
|
|
|
uint zoffs = 0;
|
|
|
|
SpriteID base = GetCanalSprite(CF_LOCKS, ti->tile);
|
|
|
|
|
|
|
|
if (base == 0) {
|
|
|
|
/* If no custom graphics, use defaults. */
|
|
|
|
base = SPR_LOCK_BASE;
|
|
|
|
zoffs = ti->z > wdts[3].delta_y ? 24 : 0;
|
|
|
|
}
|
|
|
|
|
2010-08-03 17:48:07 +00:00
|
|
|
DrawWaterTileStruct(ti, wdts, base, zoffs, PAL_NONE, CF_LOCKS);
|
2010-08-03 17:47:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Draw a ship depot tile. */
|
|
|
|
static void DrawWaterDepot(const TileInfo *ti)
|
|
|
|
{
|
|
|
|
DrawWaterClassGround(ti);
|
|
|
|
/* Skip first entry in _shipdepot_display_seq as this is the ground sprite. */
|
2010-08-03 17:48:07 +00:00
|
|
|
DrawWaterTileStruct(ti, _shipdepot_display_seq[GetSection(ti->tile)] + 1, 0, 0, COMPANY_SPRITE_COLOUR(GetTileOwner(ti->tile)), CF_END);
|
2010-08-03 17:47:43 +00:00
|
|
|
}
|
|
|
|
|
2008-02-06 16:12:23 +00:00
|
|
|
static void DrawRiverWater(const TileInfo *ti)
|
2008-01-19 17:00:54 +00:00
|
|
|
{
|
|
|
|
SpriteID image = SPR_FLAT_WATER_TILE;
|
2010-08-03 17:48:07 +00:00
|
|
|
uint offset = 0;
|
|
|
|
uint edges_offset = 0;
|
2008-01-19 17:00:54 +00:00
|
|
|
|
2010-08-03 17:48:03 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT || HasBit(_water_feature[CF_RIVER_SLOPE].flags, CFF_HAS_FLAT_SPRITE)) {
|
2008-01-19 17:00:54 +00:00
|
|
|
image = GetCanalSprite(CF_RIVER_SLOPE, ti->tile);
|
|
|
|
if (image == 0) {
|
2008-01-28 15:19:35 +00:00
|
|
|
switch (ti->tileh) {
|
|
|
|
case SLOPE_NW: image = SPR_WATER_SLOPE_Y_DOWN; break;
|
|
|
|
case SLOPE_SW: image = SPR_WATER_SLOPE_X_UP; break;
|
|
|
|
case SLOPE_SE: image = SPR_WATER_SLOPE_Y_UP; break;
|
|
|
|
case SLOPE_NE: image = SPR_WATER_SLOPE_X_DOWN; break;
|
|
|
|
default: image = SPR_FLAT_WATER_TILE; break;
|
|
|
|
}
|
2008-01-19 17:00:54 +00:00
|
|
|
} else {
|
2010-08-03 17:48:03 +00:00
|
|
|
/* Flag bit 0 indicates that the first sprite is flat water. */
|
2010-08-03 17:48:07 +00:00
|
|
|
offset = HasBit(_water_feature[CF_RIVER_SLOPE].flags, CFF_HAS_FLAT_SPRITE) ? 1 : 0;
|
2010-08-03 17:48:03 +00:00
|
|
|
|
2008-01-19 17:00:54 +00:00
|
|
|
switch (ti->tileh) {
|
2010-08-03 17:48:07 +00:00
|
|
|
case SLOPE_SE: edges_offset += 12; break;
|
|
|
|
case SLOPE_NE: offset += 1; edges_offset += 24; break;
|
|
|
|
case SLOPE_SW: offset += 2; edges_offset += 36; break;
|
|
|
|
case SLOPE_NW: offset += 3; edges_offset += 48; break;
|
2010-08-03 17:48:03 +00:00
|
|
|
default: offset = 0; break;
|
2008-01-19 17:00:54 +00:00
|
|
|
}
|
2010-08-03 17:48:03 +00:00
|
|
|
|
2010-08-03 17:48:07 +00:00
|
|
|
offset = GetCanalSpriteOffset(CF_RIVER_SLOPE, ti->tile, offset);
|
2008-01-19 17:00:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 17:48:07 +00:00
|
|
|
DrawGroundSprite(image + offset, PAL_NONE);
|
2008-01-19 17:00:54 +00:00
|
|
|
|
2008-01-28 15:19:35 +00:00
|
|
|
/* Draw river edges if available. */
|
2010-08-03 17:48:07 +00:00
|
|
|
DrawWaterEdges(false, edges_offset, ti->tile);
|
2008-01-19 17:00:54 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-10-04 17:10:57 +00:00
|
|
|
void DrawWaterClassGround(const TileInfo *ti)
|
|
|
|
{
|
2008-02-06 16:12:23 +00:00
|
|
|
switch (GetWaterClass(ti->tile)) {
|
|
|
|
case WATER_CLASS_SEA: DrawSeaWater(ti->tile); break;
|
|
|
|
case WATER_CLASS_CANAL: DrawCanalWater(ti->tile); break;
|
|
|
|
case WATER_CLASS_RIVER: DrawRiverWater(ti); break;
|
2008-07-26 16:14:10 +00:00
|
|
|
default: NOT_REACHED();
|
2008-02-06 16:12:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void DrawTile_Water(TileInfo *ti)
|
|
|
|
{
|
2006-03-31 18:36:13 +00:00
|
|
|
switch (GetWaterTileType(ti->tile)) {
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_CLEAR:
|
2008-02-06 16:12:23 +00:00
|
|
|
DrawWaterClassGround(ti);
|
2006-12-27 12:38:02 +00:00
|
|
|
DrawBridgeMiddle(ti);
|
2006-03-31 18:36:13 +00: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);
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-03-31 18:36:13 +00:00
|
|
|
|
2010-08-03 17:47:43 +00:00
|
|
|
case WATER_TILE_LOCK:
|
|
|
|
DrawWaterLock(ti);
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
2006-03-31 18:36:13 +00:00
|
|
|
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_DEPOT:
|
2010-08-03 17:47:43 +00:00
|
|
|
DrawWaterDepot(ti);
|
2006-03-31 18:36:13 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00: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 17:04:08 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawSprite(wdts++->image, PAL_NONE, x, y);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-02-22 18:27:57 +00:00
|
|
|
for (; wdts->delta_x != 0x80; wdts++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
Point pt = RemapCoords(wdts->delta_x, wdts->delta_y, wdts->delta_z);
|
2009-02-09 02:57:15 +00:00
|
|
|
DrawSprite(wdts->image, COMPANY_SPRITE_COLOUR(_local_company), x + pt.x, y + pt.y);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-06 16:32:49 +00:00
|
|
|
static uint GetSlopeZ_Water(TileIndex tile, uint x, uint y)
|
2004-09-10 19:02:27 +00:00
|
|
|
{
|
2006-08-06 16:32:49 +00:00
|
|
|
uint z;
|
2007-01-10 18:56:51 +00:00
|
|
|
Slope tileh = GetTileSlope(tile, &z);
|
2006-08-06 16:32:49 +00:00
|
|
|
|
|
|
|
return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-07-26 16:51:10 +00:00
|
|
|
static Foundation GetFoundation_Water(TileIndex tile, Slope tileh)
|
2004-09-10 19:02:27 +00:00
|
|
|
{
|
2007-07-26 16:51:10 +00:00
|
|
|
return FOUNDATION_NONE;
|
2004-08-13 18:27:33 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-31 18:36:13 +00:00
|
|
|
switch (GetWaterTileType(tile)) {
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_CLEAR:
|
2008-06-14 01:08:59 +00:00
|
|
|
switch (GetWaterClass(tile)) {
|
2009-08-05 17:59:21 +00:00
|
|
|
case WATER_CLASS_SEA: td->str = STR_LAI_WATER_DESCRIPTION_WATER; break;
|
|
|
|
case WATER_CLASS_CANAL: td->str = STR_LAI_WATER_DESCRIPTION_CANAL; break;
|
|
|
|
case WATER_CLASS_RIVER: td->str = STR_LAI_WATER_DESCRIPTION_RIVER; break;
|
2009-07-31 13:25:20 +00:00
|
|
|
default: NOT_REACHED(); break;
|
2006-03-31 18:36:13 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-08-05 17:59:21 +00:00
|
|
|
case WATER_TILE_COAST: td->str = STR_LAI_WATER_DESCRIPTION_COAST_OR_RIVERBANK; break;
|
|
|
|
case WATER_TILE_LOCK : td->str = STR_LAI_WATER_DESCRIPTION_LOCK; break;
|
2010-06-20 19:13:02 +00:00
|
|
|
case WATER_TILE_DEPOT:
|
|
|
|
td->str = STR_LAI_WATER_DESCRIPTION_SHIP_DEPOT;
|
|
|
|
td->build_date = Depot::GetByTile(tile)->build_date;
|
|
|
|
break;
|
2009-07-31 13:25:20 +00:00
|
|
|
default: NOT_REACHED(); break;
|
2006-02-01 06:32:03 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-21 22:15:39 +00:00
|
|
|
td->owner[0] = GetTileOwner(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-17 19:52:44 +00:00
|
|
|
/**
|
|
|
|
* Handle the flooding of a vehicle. This sets the vehicle state to crashed,
|
|
|
|
* creates a newsitem and dirties the necessary windows.
|
|
|
|
* @param v The vehicle to flood.
|
|
|
|
*/
|
|
|
|
static void FloodVehicle(Vehicle *v)
|
|
|
|
{
|
|
|
|
uint pass = v->Crash(true);
|
|
|
|
|
|
|
|
AI::NewEvent(v->owner, new AIEventVehicleCrashed(v->index, v->tile, AIEventVehicleCrashed::CRASH_FLOODED));
|
|
|
|
SetDParam(0, pass);
|
|
|
|
AddVehicleNewsItem(STR_NEWS_DISASTER_FLOOD_VEHICLE, NS_ACCIDENT, v->index);
|
|
|
|
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
|
|
|
|
SndPlayVehicleFx(SND_12_EXPLOSION, v);
|
|
|
|
}
|
2008-09-07 11:23:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flood a vehicle if we are allowed to flood it, i.e. when it is on the ground.
|
|
|
|
* @param v The vehicle to test for flooding.
|
|
|
|
* @param data The z of level to flood.
|
|
|
|
* @return NULL as we always want to remove everything.
|
|
|
|
*/
|
|
|
|
static Vehicle *FloodVehicleProc(Vehicle *v, void *data)
|
|
|
|
{
|
2010-08-17 19:52:44 +00:00
|
|
|
if ((v->vehstatus & VS_CRASHED) != 0) return NULL;
|
|
|
|
|
|
|
|
switch (v->type) {
|
|
|
|
default: break;
|
|
|
|
|
|
|
|
case VEH_AIRCRAFT: {
|
|
|
|
if (!IsAirportTile(v->tile) || GetTileMaxZ(v->tile) != 0) break;
|
|
|
|
if (v->subtype == AIR_SHADOW) break;
|
2008-09-07 11:23:10 +00:00
|
|
|
|
2010-08-17 19:52:44 +00:00
|
|
|
/* We compare v->z_pos against delta_z + 1 because the shadow
|
|
|
|
* is at delta_z and the actual aircraft at delta_z + 1. */
|
|
|
|
const Station *st = Station::GetByTile(v->tile);
|
|
|
|
const AirportFTAClass *airport = st->airport.GetFTA();
|
|
|
|
if (v->z_pos != airport->delta_z + 1) break;
|
|
|
|
|
|
|
|
FloodVehicle(v);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VEH_TRAIN:
|
|
|
|
case VEH_ROAD: {
|
|
|
|
byte z = *(byte*)data;
|
|
|
|
if (v->z_pos > z) break;
|
|
|
|
FloodVehicle(v->First());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-09-07 11:23:10 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-08-09 17:04:08 +00: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
|
|
|
|
*/
|
2008-09-07 11:23:10 +00:00
|
|
|
static void FloodVehicles(TileIndex tile)
|
2007-02-05 14:00:32 +00:00
|
|
|
{
|
2008-09-07 11:23:10 +00:00
|
|
|
byte z = 0;
|
|
|
|
|
2010-01-18 12:36:08 +00:00
|
|
|
if (IsAirportTile(tile)) {
|
2009-06-24 17:39:54 +00:00
|
|
|
const Station *st = Station::GetByTile(tile);
|
2010-02-22 14:17:07 +00:00
|
|
|
TILE_AREA_LOOP(tile, st->airport) {
|
|
|
|
if (st->TileBelongsToAirport(tile)) FindVehicleOnPos(tile, &z, &FloodVehicleProc);
|
2007-06-14 08:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* No vehicle could be flooded on this airport anymore */
|
2008-09-07 11:23:10 +00:00
|
|
|
return;
|
2007-06-14 08:39:27 +00:00
|
|
|
}
|
|
|
|
|
2008-09-07 11:23:10 +00:00
|
|
|
if (!IsBridgeTile(tile)) {
|
|
|
|
FindVehicleOnPos(tile, &z, &FloodVehicleProc);
|
|
|
|
return;
|
|
|
|
}
|
2007-02-05 14:00:32 +00:00
|
|
|
|
|
|
|
TileIndex end = GetOtherBridgeEnd(tile);
|
2008-09-07 11:23:10 +00:00
|
|
|
z = GetBridgeHeight(tile);
|
2007-02-05 14:00:32 +00:00
|
|
|
|
2008-09-07 11:23:10 +00:00
|
|
|
FindVehicleOnPos(tile, &z, &FloodVehicleProc);
|
|
|
|
FindVehicleOnPos(end, &z, &FloodVehicleProc);
|
2007-02-05 14:00:32 +00:00
|
|
|
}
|
|
|
|
|
2007-10-15 00:06:59 +00:00
|
|
|
/**
|
2008-01-22 17:48:08 +00:00
|
|
|
* Returns the behaviour of a tile during flooding.
|
2007-10-15 00:06:59 +00:00
|
|
|
*
|
2008-01-22 17:48:08 +00:00
|
|
|
* @return Behaviour of the tile
|
2007-10-15 00:06:59 +00:00
|
|
|
*/
|
2010-07-10 12:45:34 +00:00
|
|
|
FloodingBehaviour GetFloodingBehaviour(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-07-26 16:14:10 +00:00
|
|
|
/* FLOOD_ACTIVE: 'single-corner-raised'-coast, sea, sea-shipdepots, sea-buoys, sea-docks (water part), rail with flooded halftile, sea-water-industries, sea-oilrigs
|
2008-01-31 17:54:13 +00:00
|
|
|
* FLOOD_DRYUP: coast with more than one corner raised, coast with rail-track, coast with trees
|
2008-07-26 16:14:10 +00:00
|
|
|
* FLOOD_PASSIVE: (not used)
|
2008-01-22 17:48:08 +00:00
|
|
|
* FLOOD_NONE: canals, rivers, everything else
|
|
|
|
*/
|
|
|
|
switch (GetTileType(tile)) {
|
|
|
|
case MP_WATER:
|
|
|
|
if (IsCoast(tile)) {
|
|
|
|
Slope tileh = GetTileSlope(tile, NULL);
|
2008-01-25 15:47:58 +00:00
|
|
|
return (IsSlopeWithOneCornerRaised(tileh) ? FLOOD_ACTIVE : FLOOD_DRYUP);
|
2008-01-22 17:48:08 +00:00
|
|
|
}
|
2010-08-26 19:29:20 +00:00
|
|
|
/* FALL THROUGH */
|
|
|
|
case MP_STATION:
|
|
|
|
case MP_INDUSTRY:
|
2010-08-27 22:29:13 +00:00
|
|
|
case MP_OBJECT:
|
2010-08-26 19:29:20 +00:00
|
|
|
return (GetWaterClass(tile) == WATER_CLASS_SEA) ? FLOOD_ACTIVE : FLOOD_NONE;
|
2008-01-22 17:48:08 +00:00
|
|
|
|
|
|
|
case MP_RAILWAY:
|
2008-01-25 16:51:35 +00:00
|
|
|
if (GetRailGroundType(tile) == RAIL_GROUND_WATER) {
|
|
|
|
return (IsSlopeWithOneCornerRaised(GetTileSlope(tile, NULL)) ? FLOOD_ACTIVE : FLOOD_DRYUP);
|
|
|
|
}
|
|
|
|
return FLOOD_NONE;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-31 17:54:13 +00:00
|
|
|
case MP_TREES:
|
|
|
|
return (GetTreeGround(tile) == TREE_GROUND_SHORE ? FLOOD_DRYUP : FLOOD_NONE);
|
|
|
|
|
2008-01-22 17:48:08 +00:00
|
|
|
default:
|
|
|
|
return FLOOD_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Floods a tile.
|
|
|
|
*/
|
2009-01-21 02:31:55 +00:00
|
|
|
void DoFloodTile(TileIndex target)
|
2008-01-22 17:48:08 +00:00
|
|
|
{
|
2008-03-08 18:32:01 +00:00
|
|
|
assert(!IsTileType(target, MP_WATER));
|
2008-01-22 17:48:08 +00:00
|
|
|
|
|
|
|
bool flooded = false; // Will be set to true if something is changed.
|
|
|
|
|
2010-06-05 12:16:12 +00:00
|
|
|
Backup<CompanyByte> cur_company(_current_company, OWNER_WATER, FILE_LINE);
|
2008-01-22 17:48:08 +00:00
|
|
|
|
2008-01-31 17:54:13 +00:00
|
|
|
Slope tileh = GetTileSlope(target, NULL);
|
|
|
|
if (tileh != SLOPE_FLAT) {
|
2008-01-22 17:48:08 +00:00
|
|
|
/* make coast.. */
|
|
|
|
switch (GetTileType(target)) {
|
|
|
|
case MP_RAILWAY: {
|
2009-05-18 01:26:23 +00:00
|
|
|
if (!IsPlainRail(target)) break;
|
2008-09-07 11:23:10 +00:00
|
|
|
FloodVehicles(target);
|
2008-01-22 17:48:08 +00:00
|
|
|
flooded = FloodHalftile(target);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MP_TREES:
|
2008-01-31 17:54:13 +00:00
|
|
|
if (!IsSlopeWithOneCornerRaised(tileh)) {
|
|
|
|
SetTreeGroundDensity(target, TREE_GROUND_SHORE, 3);
|
|
|
|
MarkTileDirtyByTile(target);
|
|
|
|
flooded = true;
|
|
|
|
break;
|
|
|
|
}
|
2010-08-01 20:52:11 +00:00
|
|
|
/* FALL THROUGH */
|
|
|
|
|
2008-01-31 17:54:13 +00:00
|
|
|
case MP_CLEAR:
|
2010-01-18 22:57:21 +00:00
|
|
|
if (DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR).Succeeded()) {
|
2008-01-22 17:48:08 +00:00
|
|
|
MakeShore(target);
|
|
|
|
MarkTileDirtyByTile(target);
|
|
|
|
flooded = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Flood vehicles */
|
2008-09-07 11:23:10 +00:00
|
|
|
FloodVehicles(target);
|
2008-01-22 17:48:08 +00:00
|
|
|
|
|
|
|
/* flood flat tile */
|
2010-01-18 22:57:21 +00:00
|
|
|
if (DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR).Succeeded()) {
|
2009-10-20 12:31:11 +00:00
|
|
|
MakeSea(target);
|
2008-01-22 17:48:08 +00:00
|
|
|
MarkTileDirtyByTile(target);
|
|
|
|
flooded = true;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-10-15 00:06:59 +00:00
|
|
|
|
2008-01-22 17:48:08 +00:00
|
|
|
if (flooded) {
|
|
|
|
/* Mark surrounding canal tiles dirty too to avoid glitches */
|
2008-01-29 14:17:13 +00:00
|
|
|
MarkCanalsAndRiversAroundDirty(target);
|
2004-08-13 19:52:45 +00: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 19:52:45 +00:00
|
|
|
|
2010-05-31 20:22:57 +00:00
|
|
|
cur_company.Restore();
|
2008-01-22 17:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drys a tile up.
|
|
|
|
*/
|
|
|
|
static void DoDryUp(TileIndex tile)
|
|
|
|
{
|
2010-06-05 12:16:12 +00:00
|
|
|
Backup<CompanyByte> cur_company(_current_company, OWNER_WATER, FILE_LINE);
|
2008-01-22 17:48:08 +00:00
|
|
|
|
2008-01-25 16:51:35 +00:00
|
|
|
switch (GetTileType(tile)) {
|
|
|
|
case MP_RAILWAY:
|
2009-05-18 01:26:23 +00:00
|
|
|
assert(IsPlainRail(tile));
|
2008-01-25 16:51:35 +00:00
|
|
|
assert(GetRailGroundType(tile) == RAIL_GROUND_WATER);
|
|
|
|
|
|
|
|
RailGroundType new_ground;
|
|
|
|
switch (GetTrackBits(tile)) {
|
|
|
|
case TRACK_BIT_UPPER: new_ground = RAIL_GROUND_FENCE_HORIZ1; break;
|
|
|
|
case TRACK_BIT_LOWER: new_ground = RAIL_GROUND_FENCE_HORIZ2; break;
|
|
|
|
case TRACK_BIT_LEFT: new_ground = RAIL_GROUND_FENCE_VERT1; break;
|
|
|
|
case TRACK_BIT_RIGHT: new_ground = RAIL_GROUND_FENCE_VERT2; break;
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
SetRailGroundType(tile, new_ground);
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
break;
|
|
|
|
|
2008-01-31 17:54:13 +00:00
|
|
|
case MP_TREES:
|
|
|
|
SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 3);
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
break;
|
|
|
|
|
2008-01-25 16:51:35 +00:00
|
|
|
case MP_WATER:
|
|
|
|
assert(IsCoast(tile));
|
|
|
|
|
2010-01-18 22:57:21 +00:00
|
|
|
if (DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR).Succeeded()) {
|
2008-01-25 16:51:35 +00:00
|
|
|
MakeClear(tile, CLEAR_GRASS, 3);
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-13 19:52:45 +00:00
|
|
|
|
2010-05-31 20:22:57 +00:00
|
|
|
cur_company.Restore();
|
2008-01-22 17:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2008-03-08 18:32:01 +00:00
|
|
|
/* do not try to flood water tiles - increases performance a lot */
|
|
|
|
if (IsTileType(dest, MP_WATER)) continue;
|
2008-01-22 17:48:08 +00:00
|
|
|
|
|
|
|
uint z_dest;
|
2008-04-02 14:13:15 +00:00
|
|
|
Slope slope_dest = GetFoundationSlope(dest, &z_dest) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP;
|
2008-01-22 17:48:08 +00:00
|
|
|
if (z_dest > 0) continue;
|
|
|
|
|
|
|
|
if (!HasBit(_flood_from_dirs[slope_dest], ReverseDir(dir))) continue;
|
|
|
|
|
|
|
|
DoFloodTile(dest);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FLOOD_DRYUP: {
|
2008-04-02 14:13:15 +00:00
|
|
|
Slope slope_here = GetFoundationSlope(tile, NULL) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP;
|
2008-01-22 17:48:08 +00:00
|
|
|
uint dir;
|
2010-05-11 20:48:06 +00:00
|
|
|
FOR_EACH_SET_BIT(dir, _flood_from_dirs[slope_here]) {
|
2008-01-22 17:48:08 +00:00
|
|
|
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 19:52:45 +00:00
|
|
|
|
2008-01-22 17:48:08 +00:00
|
|
|
void ConvertGroundTilesIntoWaterTiles()
|
|
|
|
{
|
|
|
|
uint z;
|
|
|
|
|
2010-03-14 13:49:23 +00:00
|
|
|
for (TileIndex tile = 0; tile < MapSize(); ++tile) {
|
|
|
|
Slope slope = GetTileSlope(tile, &z);
|
2008-01-22 17:48:08 +00:00
|
|
|
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:
|
2009-10-20 12:31:11 +00:00
|
|
|
MakeSea(tile);
|
2008-01-22 17:48:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SLOPE_N:
|
|
|
|
case SLOPE_E:
|
|
|
|
case SLOPE_S:
|
|
|
|
case SLOPE_W:
|
|
|
|
MakeShore(tile);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
uint dir;
|
2010-05-11 20:48:06 +00:00
|
|
|
FOR_EACH_SET_BIT(dir, _flood_from_dirs[slope & ~SLOPE_STEEP]) {
|
2008-01-22 17:48:08 +00:00
|
|
|
TileIndex dest = TILE_ADD(tile, TileOffsByDir((Direction)dir));
|
2008-04-02 14:13:15 +00:00
|
|
|
Slope slope_dest = GetTileSlope(dest, NULL) & ~SLOPE_STEEP;
|
2008-01-25 15:47:58 +00:00
|
|
|
if (slope_dest == SLOPE_FLAT || IsSlopeWithOneCornerRaised(slope_dest)) {
|
2008-01-22 17:48:08 +00:00
|
|
|
MakeShore(tile);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 17:49:50 +00:00
|
|
|
static TrackStatus GetTileTrackStatus_Water(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-03 10:28:16 +00: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 18:32:34 +00:00
|
|
|
|
|
|
|
TrackBits ts;
|
|
|
|
|
2006-02-01 06:32:03 +00:00
|
|
|
if (mode != TRANSPORT_WATER) return 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-03 10:28:16 +00:00
|
|
|
switch (GetWaterTileType(tile)) {
|
2008-02-02 09:28:43 +00:00
|
|
|
case WATER_TILE_CLEAR: ts = (GetTileSlope(tile, NULL) == SLOPE_FLAT) ? TRACK_BIT_ALL : TRACK_BIT_NONE; break;
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_COAST: ts = (TrackBits)coast_tracks[GetTileSlope(tile, NULL) & 0xF]; break;
|
2008-05-14 18:31:21 +00:00
|
|
|
case WATER_TILE_LOCK: ts = DiagDirToDiagTrackBits(GetLockDirection(tile)); break;
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_DEPOT: ts = AxisToTrackBits(GetShipDepotAxis(tile)); break;
|
2006-04-03 10:28:16 +00:00
|
|
|
default: return 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-05-27 16:12:16 +00:00
|
|
|
if (TileX(tile) == 0) {
|
2007-04-06 04:10:19 +00:00
|
|
|
/* NE border: remove tracks that connects NE tile edge */
|
2006-05-27 16:12:16 +00:00
|
|
|
ts &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT);
|
|
|
|
}
|
|
|
|
if (TileY(tile) == 0) {
|
2007-04-06 04:10:19 +00:00
|
|
|
/* NW border: remove tracks that connects NW tile edge */
|
2006-05-27 16:12:16 +00:00
|
|
|
ts &= ~(TRACK_BIT_Y | TRACK_BIT_LEFT | TRACK_BIT_UPPER);
|
|
|
|
}
|
2008-02-20 17:49:50 +00:00
|
|
|
return CombineTrackStatus(TrackBitsToTrackdirBits(ts), TRACKDIR_BIT_NONE);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-01-02 22:42:05 +00:00
|
|
|
static bool ClickTile_Water(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-03-01 13:27:51 +00:00
|
|
|
if (GetWaterTileType(tile) == WATER_TILE_DEPOT) {
|
2010-08-19 13:44:41 +00:00
|
|
|
ShowDepotWindow(GetShipDepotNorthTile(tile), VEH_SHIP);
|
2009-01-02 22:42:05 +00:00
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2009-01-02 22:42:05 +00:00
|
|
|
return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
static void ChangeTileOwner_Water(TileIndex tile, Owner old_owner, Owner new_owner)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-09-30 20:39:50 +00:00
|
|
|
if (!IsTileOwner(tile, old_owner)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
if (new_owner != INVALID_OWNER) {
|
|
|
|
SetTileOwner(tile, new_owner);
|
2008-02-09 17:30:13 +00:00
|
|
|
return;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-02-09 17:30:13 +00:00
|
|
|
|
|
|
|
/* Remove depot */
|
|
|
|
if (IsShipDepot(tile)) DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
|
|
|
|
|
|
|
|
/* Set owner of canals and locks ... and also canal under dock there was before.
|
|
|
|
* Check if the new owner after removing depot isn't OWNER_WATER. */
|
2008-09-30 20:39:50 +00:00
|
|
|
if (IsTileOwner(tile, old_owner)) SetTileOwner(tile, OWNER_NONE);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-12-21 22:50:51 +00:00
|
|
|
static VehicleEnterTileStatus VehicleEnter_Water(Vehicle *v, TileIndex tile, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_CONTINUE;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 21:20:05 +00:00
|
|
|
static CommandCost TerraformTile_Water(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
|
2007-08-30 17:17:04 +00:00
|
|
|
{
|
|
|
|
/* Canals can't be terraformed */
|
2009-08-05 17:59:21 +00:00
|
|
|
if (IsWaterTile(tile) && IsCanal(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST);
|
2007-08-30 17:17:04 +00:00
|
|
|
|
|
|
|
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
extern const TileTypeProcs _tile_type_water_procs = {
|
2009-03-15 00:32:18 +00:00
|
|
|
DrawTile_Water, // draw_tile_proc
|
|
|
|
GetSlopeZ_Water, // get_slope_z_proc
|
|
|
|
ClearTile_Water, // clear_tile_proc
|
2009-06-25 20:08:59 +00:00
|
|
|
NULL, // add_accepted_cargo_proc
|
2009-03-15 00:32:18 +00:00
|
|
|
GetTileDesc_Water, // get_tile_desc_proc
|
|
|
|
GetTileTrackStatus_Water, // get_tile_track_status_proc
|
|
|
|
ClickTile_Water, // click_tile_proc
|
2009-06-25 20:08:59 +00:00
|
|
|
NULL, // animate_tile_proc
|
2009-03-15 00:32:18 +00:00
|
|
|
TileLoop_Water, // tile_loop_clear
|
|
|
|
ChangeTileOwner_Water, // change_tile_owner_clear
|
2009-06-27 17:05:20 +00:00
|
|
|
NULL, // add_produced_cargo_proc
|
2009-03-15 00:32:18 +00:00
|
|
|
VehicleEnter_Water, // vehicle_enter_tile_proc
|
|
|
|
GetFoundation_Water, // get_foundation_proc
|
|
|
|
TerraformTile_Water, // terraform_tile_proc
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|