2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00: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 19:20:15 +00:00
|
|
|
#include "station_map.h"
|
2005-02-13 11:18:02 +00:00
|
|
|
#include "table/sprites.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2004-12-15 22:18:54 +00:00
|
|
|
#include "map.h"
|
2005-01-29 12:19:05 +00:00
|
|
|
#include "tile.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "vehicle.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "town.h"
|
2004-09-03 17:57:27 +00:00
|
|
|
#include "news.h"
|
2004-11-05 23:12:33 +00:00
|
|
|
#include "sound.h"
|
2005-02-06 10:18:47 +00:00
|
|
|
#include "depot.h"
|
2005-05-02 23:59:11 +00:00
|
|
|
#include "vehicle_gui.h"
|
2005-11-18 23:41:03 +00:00
|
|
|
#include "train.h"
|
2006-03-01 21:00:44 +00:00
|
|
|
#include "water_map.h"
|
2006-12-02 09:54:49 +00:00
|
|
|
#include "newgrf.h"
|
2004-09-03 17:57:27 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
static const SpriteID _water_shore_sprites[] = {
|
2005-10-15 11:06:54 +00:00
|
|
|
0,
|
|
|
|
SPR_SHORE_TILEH_1,
|
|
|
|
SPR_SHORE_TILEH_2,
|
|
|
|
SPR_SHORE_TILEH_3,
|
|
|
|
SPR_SHORE_TILEH_4,
|
|
|
|
0,
|
|
|
|
SPR_SHORE_TILEH_6,
|
|
|
|
0,
|
|
|
|
SPR_SHORE_TILEH_8,
|
|
|
|
SPR_SHORE_TILEH_9,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
SPR_SHORE_TILEH_12,
|
|
|
|
0,
|
|
|
|
0
|
2005-08-01 16:31:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-02-05 14:00:32 +00:00
|
|
|
static Vehicle *FindFloodableVehicleOnTile(TileIndex tile);
|
2004-09-03 17:57:27 +00:00
|
|
|
static void FloodVehicle(Vehicle *v);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/** Build a ship depot.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile where ship depot is built
|
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
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-10 07:15:58 +00:00
|
|
|
TileIndex tile2;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 cost, ret;
|
2005-02-06 10:18:47 +00:00
|
|
|
Depot *depot;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00: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));
|
2005-05-09 22:33:00 +00:00
|
|
|
if (!EnsureNoVehicle(tile2)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (!IsClearWaterTile(tile) || !IsClearWaterTile(tile2))
|
|
|
|
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);
|
|
|
|
|
2006-04-10 07:15:58 +00:00
|
|
|
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2005-05-09 22:33:00 +00:00
|
|
|
if (CmdFailed(ret)) return CMD_ERROR;
|
2006-04-10 07:15:58 +00:00
|
|
|
ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2005-05-09 22:33:00 +00:00
|
|
|
if (CmdFailed(ret)) return CMD_ERROR;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// pretend that we're not making land from the water even though we actually are.
|
|
|
|
cost = 0;
|
|
|
|
|
2005-02-06 10:18:47 +00:00
|
|
|
depot = AllocateDepot();
|
2005-05-09 22:33:00 +00:00
|
|
|
if (depot == NULL) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2005-02-06 10:18:47 +00:00
|
|
|
depot->xy = tile;
|
|
|
|
depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-02-24 09:42:39 +00:00
|
|
|
MakeShipDepot(tile, _current_player, DEPOT_NORTH, axis);
|
|
|
|
MakeShipDepot(tile2, _current_player, DEPOT_SOUTH, axis);
|
2006-03-30 11:11:35 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
MarkTileDirtyByTile(tile2);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return cost + _price.build_ship_depot;
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static int32 RemoveShipDepot(TileIndex tile, uint32 flags)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile2;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-30 11:21:36 +00:00
|
|
|
if (!IsShipDepot(tile)) return CMD_ERROR;
|
2006-02-01 06:32:03 +00:00
|
|
|
if (!CheckTileOwnership(tile)) return CMD_ERROR;
|
|
|
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-30 11:21:36 +00:00
|
|
|
tile2 = GetOtherShipDepotTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-01 06:32:03 +00:00
|
|
|
if (!EnsureNoVehicle(tile2)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2006-03-30 11:21:36 +00:00
|
|
|
/* Kill the depot, which is registered at the northernmost tile. Use that one */
|
2006-08-26 14:44:55 +00:00
|
|
|
DeleteDepot(GetDepotByTile(tile2 < tile ? tile2 : tile));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-01 21:00:44 +00:00
|
|
|
MakeWater(tile);
|
|
|
|
MakeWater(tile2);
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
MarkTileDirtyByTile(tile2);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return _price.remove_ship_depot;
|
|
|
|
}
|
|
|
|
|
|
|
|
// build a shiplift
|
2006-03-08 06:55:33 +00:00
|
|
|
static int32 DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int32 ret;
|
|
|
|
int delta;
|
|
|
|
|
|
|
|
// middle tile
|
2006-04-10 07:15:58 +00: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 19:02:27 +00:00
|
|
|
|
2006-09-05 23:21:41 +00:00
|
|
|
delta = TileOffsByDiagDir(dir);
|
2004-08-09 17:04:08 +00:00
|
|
|
// lower tile
|
2006-04-10 07:15:58 +00: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 13:48:16 +00:00
|
|
|
if (GetTileSlope(tile - delta, NULL) != SLOPE_FLAT) {
|
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// upper tile
|
2006-04-10 07:15:58 +00: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 13:48:16 +00:00
|
|
|
if (GetTileSlope(tile + delta, NULL) != SLOPE_FLAT) {
|
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
|
|
|
}
|
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))) {
|
|
|
|
return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2006-06-03 15:10:39 +00:00
|
|
|
MakeLock(tile, _current_player, dir);
|
2006-03-30 11:11:35 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
MarkTileDirtyByTile(tile - delta);
|
|
|
|
MarkTileDirtyByTile(tile + delta);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return _price.clear_water * 22 >> 3;
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static int32 RemoveShiplift(TileIndex tile, uint32 flags)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-09-05 23:21:41 +00:00
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-06-03 15:10:39 +00:00
|
|
|
if (!CheckTileOwnership(tile)) return CMD_ERROR;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// make sure no vehicle is on the tile.
|
|
|
|
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(tile + delta) || !EnsureNoVehicle(tile - delta))
|
|
|
|
return CMD_ERROR;
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
DoClearSquare(tile);
|
|
|
|
DoClearSquare(tile + delta);
|
|
|
|
DoClearSquare(tile - delta);
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
return _price.clear_water * 2;
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void MarkTilesAroundDirty(TileIndex tile)
|
2004-08-09 17:04:08 +00: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-12 23:46:01 +00:00
|
|
|
/** Builds a lock (ship-lift)
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile where to place the lock
|
2005-05-12 23:46:01 +00:00
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-08 06:55:33 +00:00
|
|
|
DiagDirection dir;
|
2005-01-04 17:11:03 +00:00
|
|
|
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
2005-05-12 23:46:01 +00:00
|
|
|
|
2006-03-08 06:55:33 +00:00
|
|
|
switch (GetTileSlope(tile, NULL)) {
|
2006-04-23 13:48:16 +00: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-12 23:46:01 +00:00
|
|
|
}
|
2006-03-08 06:55:33 +00:00
|
|
|
return DoBuildShiplift(tile, dir, flags);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-12 23:46:01 +00:00
|
|
|
/** Build a piece of canal.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile end tile of stretch-dragging
|
2005-05-12 23:46:01 +00: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-12 23:46:01 +00:00
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-10 12:57:42 +00:00
|
|
|
int32 cost;
|
(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-02 23:05:09 +00:00
|
|
|
int size_x, size_y;
|
2006-04-10 07:15:58 +00:00
|
|
|
int x;
|
|
|
|
int y;
|
2005-05-12 23:46:01 +00:00
|
|
|
int sx, sy;
|
|
|
|
|
2006-01-30 17:18:45 +00:00
|
|
|
if (p1 >= MapSize()) return CMD_ERROR;
|
2007-03-10 21:44:22 +00:00
|
|
|
/* Outside of the editor you can only build canals, not oceans */
|
|
|
|
if (HASBIT(p2, 0) && _game_mode != GM_EDITOR) return CMD_ERROR;
|
2005-05-12 23:46:01 +00:00
|
|
|
|
2006-04-10 07:15:58 +00:00
|
|
|
x = TileX(tile);
|
|
|
|
y = TileY(tile);
|
2005-05-12 23:46:01 +00: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-02 23:05:09 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
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-02 23:05:09 +00:00
|
|
|
size_x = (x - sx) + 1;
|
|
|
|
size_y = (y - sy) + 1;
|
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 */
|
|
|
|
if (_game_mode != GM_EDITOR && (sx != x && sy != y)) return CMD_ERROR;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
cost = 0;
|
2005-06-25 16:44:57 +00:00
|
|
|
BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
|
2006-12-27 12:38:02 +00:00
|
|
|
int32 ret;
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
if (GetTileSlope(tile, NULL) != SLOPE_FLAT) {
|
|
|
|
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-12 12:19:25 +00:00
|
|
|
// can't make water of water!
|
2006-06-28 17:33:04 +00:00
|
|
|
if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || HASBIT(p2, 0))) 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;
|
|
|
|
cost += ret;
|
2006-06-07 19:35:21 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2007-01-04 01:10:39 +00:00
|
|
|
if (TileHeight(tile) == 0 && HASBIT(p2, 0)) {
|
2006-12-27 12:38:02 +00:00
|
|
|
MakeWater(tile);
|
|
|
|
} else {
|
|
|
|
MakeCanal(tile, _current_player);
|
|
|
|
}
|
2006-03-13 12:55:20 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
MarkTilesAroundDirty(tile);
|
|
|
|
}
|
2006-03-12 12:19:25 +00:00
|
|
|
|
|
|
|
cost += _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-02 23:05:09 +00:00
|
|
|
} END_TILE_LOOP(tile, size_x, size_y, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-12 12:19:25 +00:00
|
|
|
if (cost == 0) {
|
|
|
|
return_cmd_error(STR_1007_ALREADY_BUILT);
|
|
|
|
} else {
|
|
|
|
return cost;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static int32 ClearTile_Water(TileIndex tile, byte flags)
|
|
|
|
{
|
2006-04-03 10:50:54 +00:00
|
|
|
switch (GetWaterTileType(tile)) {
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_CLEAR:
|
2006-04-03 10:50:54 +00:00
|
|
|
if (flags & DC_NO_WATER) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-03 10:50:54 +00:00
|
|
|
// Make sure no vehicle is on the tile
|
|
|
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-03 10:50:54 +00:00
|
|
|
// Make sure it's not an edge tile.
|
|
|
|
if (!IS_INT_INSIDE(TileX(tile), 1, MapMaxX() - 1) ||
|
|
|
|
!IS_INT_INSIDE(TileY(tile), 1, MapMaxY() - 1)) {
|
|
|
|
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-06-03 15:10:39 +00:00
|
|
|
if (GetTileOwner(tile) != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR;
|
|
|
|
|
2006-02-01 06:32:03 +00:00
|
|
|
if (flags & DC_EXEC) DoClearSquare(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
return _price.clear_water;
|
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
|
|
|
|
|
|
|
// Make sure no vehicle is on the tile
|
|
|
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
|
|
|
|
|
|
|
// Make sure it's not an edge tile.
|
|
|
|
if (!IS_INT_INSIDE(TileX(tile), 1, MapMaxX() - 1) ||
|
|
|
|
!IS_INT_INSIDE(TileY(tile), 1, MapMaxY() - 1)) {
|
|
|
|
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-04-04 06:01:45 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) DoClearSquare(tile);
|
2006-04-23 13:48:16 +00:00
|
|
|
if (slope == SLOPE_N || slope == SLOPE_E || slope == SLOPE_S || slope == SLOPE_W) {
|
2006-04-04 06:01:45 +00:00
|
|
|
return _price.clear_water;
|
|
|
|
} else {
|
|
|
|
return _price.purchase_land;
|
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: {
|
2006-04-04 06:01:45 +00: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;
|
|
|
|
// move to the middle tile..
|
|
|
|
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 10:50:54 +00:00
|
|
|
if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
|
|
|
|
return RemoveShipDepot(tile, flags);
|
2006-04-03 18:12:42 +00:00
|
|
|
|
2006-04-04 06:01:45 +00:00
|
|
|
default:
|
|
|
|
NOT_REACHED();
|
|
|
|
return 0;
|
|
|
|
}
|
2004-08-09 17:04:08 +00: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 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:
|
2006-06-28 17:33:04 +00: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 19:35:21 +00:00
|
|
|
|
2007-02-02 07:48:06 +00:00
|
|
|
case MP_STATION: return IsOilRig(tile) || IsDock(tile) || IsBuoy(tile);
|
2006-12-27 12:38:02 +00:00
|
|
|
default: return false;
|
2005-01-17 09:41:46 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// draw a canal styled water tile with dikes around
|
2005-06-24 12:38:35 +00:00
|
|
|
void DrawCanalWater(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
uint wa;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// determine the edges around with water.
|
|
|
|
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 19:02:27 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
if (!(wa & 1)) DrawGroundSprite(SPR_CANALS_BASE + 57, PAL_NONE);
|
|
|
|
if (!(wa & 2)) DrawGroundSprite(SPR_CANALS_BASE + 58, PAL_NONE);
|
|
|
|
if (!(wa & 4)) DrawGroundSprite(SPR_CANALS_BASE + 59, PAL_NONE);
|
|
|
|
if (!(wa & 8)) DrawGroundSprite(SPR_CANALS_BASE + 60, PAL_NONE);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// right corner
|
2006-02-06 09:18:04 +00:00
|
|
|
switch (wa & 0x03) {
|
2007-01-14 19:57:49 +00:00
|
|
|
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 4, PAL_NONE); break;
|
|
|
|
case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 8, PAL_NONE); break;
|
2006-02-06 09:18:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// bottom corner
|
2006-02-06 09:18:04 +00:00
|
|
|
switch (wa & 0x06) {
|
2007-01-14 19:57:49 +00:00
|
|
|
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 5, PAL_NONE); break;
|
|
|
|
case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 9, PAL_NONE); break;
|
2006-02-06 09:18:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// left corner
|
2006-02-06 09:18:04 +00:00
|
|
|
switch (wa & 0x0C) {
|
2007-01-14 19:57:49 +00:00
|
|
|
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 6, PAL_NONE); break;
|
|
|
|
case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 10, PAL_NONE); break;
|
2006-02-06 09:18:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// upper corner
|
2006-02-06 09:18:04 +00:00
|
|
|
switch (wa & 0x09) {
|
2007-01-14 19:57:49 +00:00
|
|
|
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 7, PAL_NONE); break;
|
|
|
|
case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 11, PAL_NONE); break;
|
2006-02-06 09:18:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct LocksDrawTileStruct {
|
2004-08-09 17:04:08 +00: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 17:04:08 +00:00
|
|
|
|
|
|
|
#include "table/water_land.h"
|
|
|
|
|
2005-09-18 20:56:44 +00: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 17:04:08 +00:00
|
|
|
{
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(wdts++->image, PAL_NONE);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-02-22 18:27:57 +00:00
|
|
|
for (; wdts->delta_x != 0x80; wdts++) {
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID image = wdts->image + base;
|
|
|
|
SpriteID pal;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (_display_opt & DO_TRANS_BUILDINGS) {
|
2007-01-14 19:57:49 +00:00
|
|
|
SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
|
|
|
|
pal = PALETTE_TO_TRANSPARENT;
|
2004-11-23 22:36:11 +00:00
|
|
|
} else {
|
2007-01-14 19:57:49 +00:00
|
|
|
pal = palette;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-01-14 19:57:49 +00:00
|
|
|
|
|
|
|
AddSortableSpriteToDraw(image, pal,
|
|
|
|
ti->x + wdts->delta_x, ti->y + wdts->delta_y,
|
|
|
|
wdts->width, wdts->height,
|
|
|
|
wdts->unk, ti->z + wdts->delta_z);
|
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:
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(SPR_FLAT_WATER_TILE, PAL_NONE);
|
2006-06-28 17:33:04 +00:00
|
|
|
if (ti->z != 0 || !IsTileOwner(ti->tile, OWNER_WATER)) DrawCanalWater(ti->tile);
|
2006-12-27 12:38:02 +00:00
|
|
|
DrawBridgeMiddle(ti);
|
2006-03-31 18:36:13 +00:00
|
|
|
break;
|
|
|
|
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_COAST:
|
2006-04-23 13:48:16 +00:00
|
|
|
assert(!IsSteepSlope(ti->tileh));
|
2006-12-02 09:54:49 +00:00
|
|
|
if (_coast_base != 0) {
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(_coast_base + ti->tileh, PAL_NONE);
|
2006-12-02 09:54:49 +00:00
|
|
|
} else {
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(_water_shore_sprites[ti->tileh], PAL_NONE);
|
2006-12-02 09:54:49 +00:00
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
DrawBridgeMiddle(ti);
|
2006-03-31 18:36:13 +00:00
|
|
|
break;
|
|
|
|
|
2007-03-01 13:27:51 +00:00
|
|
|
case WATER_TILE_LOCK: {
|
2006-04-03 10:50:54 +00:00
|
|
|
const WaterDrawTileStruct *t = _shiplift_display_seq[GetSection(ti->tile)];
|
2006-03-31 18:36:13 +00: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 10:50:54 +00:00
|
|
|
DrawWaterStuff(ti, _shipdepot_display_seq[GetSection(ti->tile)], PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), 0);
|
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);
|
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 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
|
|
|
}
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
static Slope GetSlopeTileh_Water(TileIndex tile, Slope tileh)
|
2004-09-10 19:02:27 +00:00
|
|
|
{
|
2006-04-02 12:49:18 +00:00
|
|
|
return tileh;
|
2004-08-13 18:27:33 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void GetAcceptedCargo_Water(TileIndex tile, AcceptedCargo ac)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* not used */
|
|
|
|
}
|
|
|
|
|
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:
|
2006-06-28 17:33:04 +00:00
|
|
|
if (TilePixelHeight(tile) == 0 || IsTileOwner(tile, OWNER_WATER)) {
|
2006-03-31 18:36:13 +00: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 18:36:13 +00:00
|
|
|
default: assert(0); break;
|
2006-02-01 06:32:03 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-06-04 11:56:32 +00:00
|
|
|
td->owner = GetTileOwner(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void AnimateTile_Water(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* not used */
|
|
|
|
}
|
|
|
|
|
2005-01-20 18:18:32 +00:00
|
|
|
static void TileLoopWaterHelper(TileIndex tile, const TileIndexDiffC *offs)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-20 18:18:32 +00:00
|
|
|
TileIndex target = TILE_ADD(tile, ToTileIndexDiff(offs[0]));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// type of this tile mustn't be water already.
|
2005-11-14 19:48:04 +00:00
|
|
|
if (IsTileType(target, MP_WATER)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-20 18:18:32 +00:00
|
|
|
if (TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[1]))) != 0 ||
|
2005-11-14 19:48:04 +00:00
|
|
|
TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[2]))) != 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-20 18:18:32 +00:00
|
|
|
if (TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[3]))) != 0 ||
|
|
|
|
TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[4]))) != 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
// make coast..
|
2005-01-29 15:12:40 +00:00
|
|
|
switch (GetTileType(target)) {
|
2005-01-20 18:19:37 +00:00
|
|
|
case MP_RAILWAY: {
|
2006-03-19 12:06:12 +00:00
|
|
|
TrackBits tracks;
|
2006-04-23 13:48:16 +00:00
|
|
|
Slope slope;
|
2006-03-19 12:06:12 +00:00
|
|
|
|
2006-03-19 19:55:43 +00:00
|
|
|
if (!IsPlainRailTile(target)) break;
|
2006-03-19 12:06:12 +00:00
|
|
|
|
|
|
|
tracks = GetTrackBits(target);
|
|
|
|
slope = GetTileSlope(target, NULL);
|
2005-01-20 18:19:37 +00:00
|
|
|
if (!(
|
2006-04-23 13:48:16 +00:00
|
|
|
(slope == SLOPE_W && tracks == TRACK_BIT_RIGHT) ||
|
|
|
|
(slope == SLOPE_S && tracks == TRACK_BIT_UPPER) ||
|
|
|
|
(slope == SLOPE_E && tracks == TRACK_BIT_LEFT) ||
|
|
|
|
(slope == SLOPE_N && tracks == TRACK_BIT_LOWER)
|
2006-03-19 12:06:12 +00:00
|
|
|
)) {
|
2005-01-20 18:19:37 +00:00
|
|
|
break;
|
2006-03-19 12:06:12 +00:00
|
|
|
}
|
2005-01-20 18:19:37 +00:00
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
2005-01-20 18:18:32 +00:00
|
|
|
case MP_CLEAR:
|
|
|
|
case MP_TREES:
|
|
|
|
_current_player = OWNER_WATER;
|
2006-04-10 07:15:58 +00:00
|
|
|
if (!CmdFailed(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
|
2006-03-01 21:00:44 +00:00
|
|
|
MakeShore(target);
|
|
|
|
MarkTileDirtyByTile(target);
|
2005-01-20 18:18:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_current_player = OWNER_WATER;
|
2007-02-05 14:00:32 +00:00
|
|
|
|
|
|
|
Vehicle *v = FindFloodableVehicleOnTile(target);
|
|
|
|
if (v != NULL) FloodVehicle(v);
|
2005-01-20 18:18:32 +00:00
|
|
|
|
2006-04-10 07:15:58 +00:00
|
|
|
if (!CmdFailed(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
|
2006-03-01 21:00:44 +00:00
|
|
|
MakeWater(target);
|
|
|
|
MarkTileDirtyByTile(target);
|
2004-09-03 17:57:27 +00:00
|
|
|
}
|
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
|
|
|
|
* @return a vehicle too flood or NULL when there is no vehicle too flood.
|
|
|
|
*/
|
|
|
|
static Vehicle *FindFloodableVehicleOnTile(TileIndex tile)
|
|
|
|
{
|
|
|
|
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 17:57:27 +00:00
|
|
|
static void FloodVehicle(Vehicle *v)
|
|
|
|
{
|
|
|
|
if (!(v->vehstatus & VS_CRASHED)) {
|
2004-09-06 21:20:01 +00:00
|
|
|
uint16 pass = 0;
|
2004-09-03 17:57:27 +00:00
|
|
|
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_ROAD) { // flood bus/truck
|
2006-08-28 18:53:03 +00:00
|
|
|
pass = 1; // driver
|
2004-09-03 17:57:27 +00:00
|
|
|
if (v->cargo_type == CT_PASSENGERS)
|
|
|
|
pass += v->cargo_count;
|
|
|
|
|
|
|
|
v->vehstatus |= VS_CRASHED;
|
2006-08-28 18:53:03 +00:00
|
|
|
v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast
|
2004-12-10 18:16:08 +00:00
|
|
|
RebuildVehicleLists();
|
2007-03-08 16:27:54 +00:00
|
|
|
} else if (v->type == VEH_TRAIN) {
|
2006-07-26 03:33:12 +00:00
|
|
|
Vehicle *u;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-09-03 17:57:27 +00:00
|
|
|
v = GetFirstVehicleInChain(v);
|
|
|
|
u = v;
|
2005-11-18 23:41:03 +00:00
|
|
|
if (IsFrontEngine(v)) pass = 4; // driver
|
2004-09-03 17:57:27 +00:00
|
|
|
|
|
|
|
// crash all wagons, and count passangers
|
|
|
|
BEGIN_ENUM_WAGONS(v)
|
|
|
|
if (v->cargo_type == CT_PASSENGERS) pass += v->cargo_count;
|
|
|
|
v->vehstatus |= VS_CRASHED;
|
2007-02-05 14:00:32 +00:00
|
|
|
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
|
2004-09-03 17:57:27 +00:00
|
|
|
END_ENUM_WAGONS(v)
|
|
|
|
|
|
|
|
v = u;
|
|
|
|
v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
|
2004-12-10 18:16:08 +00:00
|
|
|
RebuildVehicleLists();
|
2005-10-23 13:04:44 +00:00
|
|
|
} else {
|
2004-09-06 21:20:01 +00:00
|
|
|
return;
|
2005-10-23 13:04:44 +00:00
|
|
|
}
|
2004-09-03 17:57:27 +00:00
|
|
|
|
2004-12-21 23:27:58 +00:00
|
|
|
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
|
2004-09-03 17:57:27 +00:00
|
|
|
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, pass);
|
2004-09-03 17:57:27 +00:00
|
|
|
AddNewsItem(STR_B006_FLOOD_VEHICLE_DESTROYED,
|
|
|
|
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
|
|
|
|
v->index,
|
|
|
|
0);
|
2005-10-23 13:04:44 +00: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 17:57:27 +00:00
|
|
|
}
|
|
|
|
|
2006-06-28 18:37:53 +00:00
|
|
|
// called from tunnelbridge_cmd, and by TileLoop_Industry()
|
2005-06-24 12:38:35 +00:00
|
|
|
void TileLoop_Water(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-06 11:39:00 +00:00
|
|
|
static const TileIndexDiffC _tile_loop_offs_array[][5] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
// tile to mod shore? shore?
|
2005-01-06 11:39:00 +00:00
|
|
|
{{-1, 0}, {0, 0}, {0, 1}, {-1, 0}, {-1, 1}},
|
|
|
|
{{ 0, 1}, {0, 1}, {1, 1}, { 0, 2}, { 1, 2}},
|
|
|
|
{{ 1, 0}, {1, 0}, {1, 1}, { 2, 0}, { 2, 1}},
|
|
|
|
{{ 0, -1}, {0, 0}, {1, 0}, { 0, -1}, { 1, -1}}
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2007-02-07 18:01:26 +00:00
|
|
|
/* Ensure sea-level canals and buoys on canal borders do not flood */
|
|
|
|
if ((IsTileType(tile, MP_WATER) || IsBuoyTile(tile)) && !IsTileOwner(tile, OWNER_WATER)) return;
|
2006-06-28 17:33:04 +00:00
|
|
|
|
2005-01-07 17:02:43 +00:00
|
|
|
if (IS_INT_INSIDE(TileX(tile), 1, MapSizeX() - 3 + 1) &&
|
|
|
|
IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) {
|
2006-02-06 09:18:04 +00:00
|
|
|
uint i;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (i = 0; i != lengthof(_tile_loop_offs_array); i++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
TileLoopWaterHelper(tile, _tile_loop_offs_array[i]);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-25 17:37:32 +00:00
|
|
|
// _current_player can be changed by TileLoopWaterHelper.. reset it back
|
|
|
|
// here
|
|
|
|
_current_player = OWNER_NONE;
|
2004-08-13 19:52:45 +00:00
|
|
|
|
|
|
|
// edges
|
2006-02-01 06:32:03 +00:00
|
|
|
if (TileX(tile) == 0 && IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) { //NE
|
2004-08-13 19:52:45 +00:00
|
|
|
TileLoopWaterHelper(tile, _tile_loop_offs_array[2]);
|
2006-02-01 06:32:03 +00:00
|
|
|
}
|
2004-08-13 19:52:45 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (TileX(tile) == MapSizeX() - 2 && IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) { //SW
|
2004-08-13 19:52:45 +00:00
|
|
|
TileLoopWaterHelper(tile, _tile_loop_offs_array[0]);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-13 19:52:45 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (TileY(tile) == 0 && IS_INT_INSIDE(TileX(tile), 1, MapSizeX() - 3 + 1)) { //NW
|
2004-08-13 19:52:45 +00:00
|
|
|
TileLoopWaterHelper(tile, _tile_loop_offs_array[1]);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-13 19:52:45 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (TileY(tile) == MapSizeY() - 2 && IS_INT_INSIDE(TileX(tile), 1, MapSizeX() - 3 + 1)) { //SE
|
2004-08-13 19:52:45 +00:00
|
|
|
TileLoopWaterHelper(tile, _tile_loop_offs_array[3]);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static uint32 GetTileTrackStatus_Water(TileIndex tile, TransportType mode)
|
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)) {
|
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;
|
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) {
|
|
|
|
// NE border: remove tracks that connects NE tile edge
|
|
|
|
ts &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT);
|
|
|
|
}
|
|
|
|
if (TileY(tile) == 0) {
|
|
|
|
// NW border: remove tracks that connects NW tile edge
|
|
|
|
ts &= ~(TRACK_BIT_Y | TRACK_BIT_LEFT | TRACK_BIT_UPPER);
|
|
|
|
}
|
|
|
|
return ts * 0x101;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void 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) {
|
2006-04-03 10:28:16 +00:00
|
|
|
TileIndex tile2 = GetOtherShipDepotTile(tile);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-03-08 16:27:54 +00:00
|
|
|
ShowDepotWindow(tile < tile2 ? tile : tile2, VEH_SHIP);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static void ChangeTileOwner_Water(TileIndex tile, PlayerID old_player, PlayerID new_player)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-06-04 11:56:32 +00:00
|
|
|
if (!IsTileOwner(tile, old_player)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-14 15:49:43 +00:00
|
|
|
if (new_player != PLAYER_SPECTATOR) {
|
2005-06-04 12:13:24 +00:00
|
|
|
SetTileOwner(tile, new_player);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2006-04-10 07:15:58 +00:00
|
|
|
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static uint32 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
extern const TileTypeProcs _tile_type_water_procs = {
|
2006-08-22 14:38:37 +00: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 */
|
|
|
|
GetSlopeTileh_Water, /* get_slope_tileh_proc */
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|