2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/** @file road_cmd.cpp */
|
|
|
|
|
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-01 08:56:38 +00:00
|
|
|
#include "rail_map.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "road_map.h"
|
2007-12-18 20:38:16 +00:00
|
|
|
#include "road_internal.h"
|
2006-08-06 18:36:36 +00:00
|
|
|
#include "sprite.h"
|
2007-12-21 22:50:51 +00:00
|
|
|
#include "tile_cmd.h"
|
2007-03-20 13:47:00 +00:00
|
|
|
#include "landscape.h"
|
2006-03-24 12:00:24 +00:00
|
|
|
#include "town_map.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"
|
2006-05-27 16:12:16 +00:00
|
|
|
#include "yapf/yapf.h"
|
2005-02-06 10:18:47 +00:00
|
|
|
#include "depot.h"
|
2007-04-27 21:35:02 +00:00
|
|
|
#include "newgrf.h"
|
2007-05-24 09:31:09 +00:00
|
|
|
#include "station_map.h"
|
|
|
|
#include "tunnel_map.h"
|
2007-08-02 22:33:53 +00:00
|
|
|
#include "misc/autoptr.hpp"
|
2008-01-07 00:57:19 +00:00
|
|
|
#include "variables.h"
|
2007-09-14 22:27:40 +00:00
|
|
|
#include "autoslope.h"
|
2007-11-10 01:17:15 +00:00
|
|
|
#include "transparency.h"
|
2007-12-16 15:38:51 +00:00
|
|
|
#include "tunnelbridge_map.h"
|
2007-12-19 19:44:29 +00:00
|
|
|
#include "window_func.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"
|
|
|
|
#include "vehicle_base.h"
|
2007-12-29 09:24:26 +00:00
|
|
|
#include "sound_func.h"
|
2008-01-17 19:49:06 +00:00
|
|
|
#include "road_func.h"
|
2008-01-23 22:34:04 +00:00
|
|
|
#include "tunnelbridge.h"
|
2007-12-16 15:38:51 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/sprites.h"
|
|
|
|
#include "table/strings.h"
|
2007-09-14 22:27:40 +00:00
|
|
|
|
|
|
|
#define M(x) (1 << (x))
|
|
|
|
/* Level crossings may only be built on these slopes */
|
|
|
|
static const uint32 VALID_LEVEL_CROSSING_SLOPES = (M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT));
|
|
|
|
#undef M
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-03-27 14:26:31 +00:00
|
|
|
/* Invalid RoadBits on slopes */
|
|
|
|
static const RoadBits _invalid_tileh_slopes_road[2][15] = {
|
|
|
|
/* The inverse of the mixable RoadBits on a leveled slope */
|
|
|
|
{
|
|
|
|
ROAD_NONE, // SLOPE_FLAT
|
|
|
|
ROAD_NE | ROAD_SE, // SLOPE_W
|
|
|
|
ROAD_NE | ROAD_NW, // SLOPE_S
|
|
|
|
|
|
|
|
ROAD_NE, // SLOPE_SW
|
|
|
|
ROAD_NW | ROAD_SW, // SLOPE_E
|
|
|
|
ROAD_NONE, // SLOPE_EW
|
|
|
|
|
|
|
|
ROAD_NW, // SLOPE_SE
|
|
|
|
ROAD_NONE, // SLOPE_WSE
|
|
|
|
ROAD_SE | ROAD_SW, // SLOPE_N
|
|
|
|
|
|
|
|
ROAD_SE, // SLOPE_NW
|
|
|
|
ROAD_NONE, // SLOPE_NS
|
|
|
|
ROAD_NONE, // SLOPE_ENW
|
|
|
|
|
|
|
|
ROAD_SW, // SLOPE_NE
|
|
|
|
ROAD_NONE, // SLOPE_SEN
|
|
|
|
ROAD_NONE // SLOPE_NWS
|
|
|
|
},
|
|
|
|
/* The inverse of the allowed straight roads on a slope
|
|
|
|
* (with and without a foundation). */
|
|
|
|
{
|
|
|
|
ROAD_NONE, // SLOPE_FLAT
|
|
|
|
ROAD_NONE, // SLOPE_W Foundation
|
|
|
|
ROAD_NONE, // SLOPE_S Foundation
|
|
|
|
|
|
|
|
ROAD_Y, // SLOPE_SW
|
|
|
|
ROAD_NONE, // SLOPE_E Foundation
|
|
|
|
ROAD_ALL, // SLOPE_EW
|
|
|
|
|
|
|
|
ROAD_X, // SLOPE_SE
|
|
|
|
ROAD_ALL, // SLOPE_WSE
|
|
|
|
ROAD_NONE, // SLOPE_N Foundation
|
|
|
|
|
|
|
|
ROAD_X, // SLOPE_NW
|
|
|
|
ROAD_ALL, // SLOPE_NS
|
|
|
|
ROAD_ALL, // SLOPE_ENW
|
|
|
|
|
|
|
|
ROAD_Y, // SLOPE_NE
|
|
|
|
ROAD_ALL, // SLOPE_SEN
|
|
|
|
ROAD_ALL // SLOPE_NW
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-01-23 00:36:48 +00:00
|
|
|
Foundation GetRoadFoundation(Slope tileh, RoadBits bits);
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, bool *edge_road, RoadType rt)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
*edge_road = true;
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
if (_game_mode == GM_EDITOR || remove == ROAD_NONE) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-05-30 13:16:45 +00:00
|
|
|
/* Water can always flood and towns can always remove "normal" road pieces.
|
|
|
|
* Towns are not be allowed to remove non "normal" road pieces, like tram
|
|
|
|
* tracks as that would result in trams that cannot turn. */
|
|
|
|
if (_current_player == OWNER_WATER ||
|
|
|
|
(rt == ROADTYPE_ROAD && !IsValidPlayer(_current_player))) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Only do the special processing if the road is owned
|
|
|
|
* by a town */
|
2006-10-14 22:22:48 +00:00
|
|
|
if (owner != OWNER_TOWN) return (owner == OWNER_NONE) || CheckOwnership(owner);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-13 21:15:00 +00:00
|
|
|
if (_cheats.magic_bulldozer.value) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Get a bitmask of which neighbouring roads has a tile */
|
2008-03-25 18:59:25 +00:00
|
|
|
RoadBits n = ROAD_NONE;
|
|
|
|
RoadBits present = GetAnyRoadBits(tile, rt);
|
2007-05-20 19:14:08 +00:00
|
|
|
if (present & ROAD_NE && GetAnyRoadBits(TILE_ADDXY(tile, -1, 0), rt) & ROAD_SW) n |= ROAD_NE;
|
|
|
|
if (present & ROAD_SE && GetAnyRoadBits(TILE_ADDXY(tile, 0, 1), rt) & ROAD_NW) n |= ROAD_SE;
|
|
|
|
if (present & ROAD_SW && GetAnyRoadBits(TILE_ADDXY(tile, 1, 0), rt) & ROAD_NE) n |= ROAD_SW;
|
|
|
|
if (present & ROAD_NW && GetAnyRoadBits(TILE_ADDXY(tile, 0, -1), rt) & ROAD_SE) n |= ROAD_NW;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* If 0 or 1 bits are set in n, or if no bits that match the bits to remove,
|
|
|
|
* then allow it */
|
2008-03-25 18:59:25 +00:00
|
|
|
if (KillFirstBit(n) != ROAD_NONE && (n & remove) != ROAD_NONE) {
|
2004-08-09 17:04:08 +00:00
|
|
|
*edge_road = false;
|
2007-03-28 20:41:35 +00:00
|
|
|
/* you can remove all kind of roads with extra dynamite */
|
2006-02-13 21:15:00 +00:00
|
|
|
if (_patches.extra_dynamite) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-03-25 18:59:25 +00:00
|
|
|
const Town *t = ClosestTownFromTile(tile, (uint)-1);
|
2005-04-03 13:37:35 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, t->index);
|
2004-08-09 17:04:08 +00:00
|
|
|
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
static bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, bool *edge_road, RoadType rt)
|
2007-02-23 00:17:46 +00:00
|
|
|
{
|
2007-05-20 19:14:08 +00:00
|
|
|
return CheckAllowRemoveRoad(tile, remove, GetRoadOwner(tile, rt), edge_road, rt);
|
2007-02-23 00:17:46 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-28 12:40:31 +00:00
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/** Delete a piece of road.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile where to remove road from
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2008-01-28 12:40:31 +00:00
|
|
|
* @param pieces roadbits to remove
|
|
|
|
* @param rt roadtype to remove
|
|
|
|
* @param crossing_check should we check if there is a tram track when we are removing road from crossing?
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2008-01-28 12:40:31 +00:00
|
|
|
static CommandCost RemoveRoad(TileIndex tile, uint32 flags, RoadBits pieces, RoadType rt, bool crossing_check)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-03-28 20:41:35 +00:00
|
|
|
/* cost for removing inner/edge -roads */
|
2005-04-03 13:37:35 +00:00
|
|
|
static const uint16 road_remove_cost[2] = {50, 18};
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/* true if the roadpiece was always removeable,
|
|
|
|
* false if it was a center piece. Affects town ratings drop */
|
2004-08-09 17:04:08 +00:00
|
|
|
bool edge_road;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-07-10 22:45:09 +00:00
|
|
|
Town *t = NULL;
|
2007-05-24 09:31:09 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2007-07-29 23:42:59 +00:00
|
|
|
case MP_ROAD:
|
2007-07-10 22:45:09 +00:00
|
|
|
if (_game_mode != GM_EDITOR && GetRoadOwner(tile, rt) == OWNER_TOWN) t = GetTownByTile(tile);
|
2007-12-15 13:59:38 +00:00
|
|
|
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
2007-05-24 09:31:09 +00:00
|
|
|
break;
|
2005-07-15 21:17:38 +00:00
|
|
|
|
2007-05-24 09:31:09 +00:00
|
|
|
case MP_STATION:
|
|
|
|
if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
|
2007-12-15 13:59:38 +00:00
|
|
|
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
2007-05-24 09:31:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_TUNNELBRIDGE:
|
2008-01-23 14:51:36 +00:00
|
|
|
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
|
|
|
|
if (GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL) return CMD_ERROR;
|
|
|
|
break;
|
2007-05-24 09:31:09 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2005-04-03 13:37:35 +00:00
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadTypes rts = GetRoadTypes(tile);
|
|
|
|
/* The tile doesn't have the given road type */
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!HasBit(rts, rt)) return CMD_ERROR;
|
2007-02-24 09:42:39 +00:00
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
if (!CheckAllowRemoveRoad(tile, pieces, &edge_road, rt)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* check if you're allowed to remove the street owned by a town
|
|
|
|
* removal allowance depends on difficulty setting */
|
2006-12-27 12:38:02 +00:00
|
|
|
if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR;
|
2006-02-21 18:07:35 +00:00
|
|
|
|
2007-07-29 23:42:59 +00:00
|
|
|
if (!IsTileType(tile, MP_ROAD)) {
|
2007-05-24 09:31:09 +00:00
|
|
|
/* If it's the last roadtype, just clear the whole tile */
|
|
|
|
if (rts == RoadTypeToRoadTypes(rt)) return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
|
|
2008-01-09 16:55:48 +00:00
|
|
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
2007-05-24 09:31:09 +00:00
|
|
|
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
2008-01-04 19:45:29 +00:00
|
|
|
TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
|
2007-05-24 09:31:09 +00:00
|
|
|
/* Pay for *every* tile of the bridge or tunnel */
|
2008-01-23 22:34:04 +00:00
|
|
|
cost.AddCost((GetTunnelBridgeLength(other_end, tile) + 2) * _price.remove_road);
|
2007-05-24 09:31:09 +00:00
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
SetRoadTypes(other_end, GetRoadTypes(other_end) & ~RoadTypeToRoadTypes(rt));
|
|
|
|
SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
|
|
|
|
|
|
|
|
/* Mark tiles diry that have been repaved */
|
2007-05-26 22:01:49 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2007-05-24 09:31:09 +00:00
|
|
|
MarkTileDirtyByTile(other_end);
|
|
|
|
if (IsBridge(tile)) {
|
2007-12-16 15:38:51 +00:00
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
|
2007-05-24 09:31:09 +00:00
|
|
|
|
2007-05-26 21:45:16 +00:00
|
|
|
for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t);
|
2007-05-24 09:31:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(_price.remove_road);
|
2007-05-24 09:31:09 +00:00
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
}
|
2008-01-09 16:55:48 +00:00
|
|
|
return cost;
|
2007-05-24 09:31:09 +00:00
|
|
|
}
|
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
switch (GetRoadTileType(tile)) {
|
|
|
|
case ROAD_TILE_NORMAL: {
|
2008-03-27 14:26:31 +00:00
|
|
|
const Slope tileh = GetTileSlope(tile, NULL);
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadBits present = GetRoadBits(tile, rt);
|
2008-03-27 14:26:31 +00:00
|
|
|
const RoadBits other = GetOtherRoadBits(tile, rt);
|
|
|
|
const Foundation f = GetRoadFoundation(tileh, present);
|
2006-06-07 19:35:21 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
|
2006-06-19 17:22:57 +00:00
|
|
|
|
2008-03-27 14:26:31 +00:00
|
|
|
/* Autocomplete to a straight road
|
|
|
|
* @li on steep slopes
|
|
|
|
* @li if the bits of the other roadtypes result in another foundation
|
|
|
|
* @li if build on slopes is disabled */
|
2008-03-27 15:29:42 +00:00
|
|
|
if (IsSteepSlope(tileh) || (IsStraightRoad(other) &&
|
|
|
|
(other & _invalid_tileh_slopes_road[0][tileh & SLOPE_ELEVATED]) != ROAD_NONE) ||
|
|
|
|
(tileh != SLOPE_FLAT && !_patches.build_on_slopes)) {
|
2008-03-25 18:59:25 +00:00
|
|
|
pieces |= MirrorRoadBits(pieces);
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
2006-02-21 18:07:35 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* limit the bits to delete to the existing bits. */
|
2008-03-25 18:59:25 +00:00
|
|
|
pieces &= present;
|
|
|
|
if (pieces == ROAD_NONE) return CMD_ERROR;
|
2006-06-07 19:35:21 +00:00
|
|
|
|
2008-03-27 14:26:31 +00:00
|
|
|
/* Now set present what it will be after the remove */
|
|
|
|
present ^= pieces;
|
|
|
|
|
|
|
|
/* Check for invalid RoadBit combinations on slopes */
|
|
|
|
if (tileh != SLOPE_FLAT && present != ROAD_NONE &&
|
|
|
|
(present & _invalid_tileh_slopes_road[0][tileh & SLOPE_ELEVATED]) == present) {
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
2008-01-09 17:47:05 +00:00
|
|
|
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
|
2006-12-27 12:38:02 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2007-05-20 22:04:24 +00:00
|
|
|
if (present == ROAD_NONE) {
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
|
|
|
|
if (rts == ROADTYPES_NONE) {
|
2007-09-07 21:17:01 +00:00
|
|
|
/* Includes MarkTileDirtyByTile() */
|
2007-05-20 19:14:08 +00:00
|
|
|
DoClearSquare(tile);
|
|
|
|
} else {
|
2007-05-20 22:04:24 +00:00
|
|
|
SetRoadBits(tile, ROAD_NONE, rt);
|
2007-05-20 19:14:08 +00:00
|
|
|
SetRoadTypes(tile, rts);
|
2007-09-07 21:17:01 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2007-05-20 19:14:08 +00:00
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
} else {
|
2007-05-31 15:15:00 +00:00
|
|
|
/* When bits are removed, you *always* end up with something that
|
|
|
|
* is not a complete straight road tile. However, trams do not have
|
|
|
|
* onewayness, so they cannot remove it either. */
|
|
|
|
if (rt != ROADTYPE_TRAM) SetDisallowedRoadDirections(tile, DRD_NONE);
|
2007-05-20 19:14:08 +00:00
|
|
|
SetRoadBits(tile, present, rt);
|
2006-12-27 12:38:02 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
2008-03-27 14:26:31 +00:00
|
|
|
|
|
|
|
/* If we change the foundation we have to pay for it. */
|
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, CountBits(pieces) * _price.remove_road +
|
|
|
|
((GetRoadFoundation(tileh, present) != f) ? _price.terraform : (Money)0));
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
case ROAD_TILE_CROSSING: {
|
|
|
|
if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) {
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2005-04-03 13:37:35 +00:00
|
|
|
|
2007-05-26 07:58:49 +00:00
|
|
|
/* Don't allow road to be removed from the crossing when there is tram;
|
|
|
|
* we can't draw the crossing without trambits ;) */
|
2008-02-14 15:59:16 +00:00
|
|
|
if (rt == ROADTYPE_ROAD && HasTileRoadType(tile, ROADTYPE_TRAM) && (flags & DC_EXEC || crossing_check)) return CMD_ERROR;
|
2007-05-26 07:58:49 +00:00
|
|
|
|
2008-01-09 17:47:05 +00:00
|
|
|
if (rt == ROADTYPE_ROAD) {
|
|
|
|
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
|
|
|
|
}
|
2008-01-03 23:54:23 +00:00
|
|
|
|
2008-01-09 17:47:05 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
|
|
|
|
if (rts == ROADTYPES_NONE) {
|
|
|
|
MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GetRailType(tile));
|
|
|
|
} else {
|
|
|
|
SetRoadTypes(tile, rts);
|
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2007-01-10 18:56:51 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-01-09 16:55:48 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_road * 2);
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
default:
|
|
|
|
case ROAD_TILE_DEPOT:
|
|
|
|
return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-28 12:40:31 +00:00
|
|
|
/** Delete a piece of road.
|
|
|
|
* @param tile tile where to remove road from
|
|
|
|
* @param flags operation to perform
|
|
|
|
* @param p1 bit 0..3 road pieces to remove (RoadBits)
|
|
|
|
* bit 4..5 road type
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
|
|
|
CommandCost CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
|
|
|
RoadType rt = (RoadType)GB(p1, 4, 2);
|
|
|
|
if (!IsValidRoadType(rt)) return CMD_ERROR;
|
|
|
|
|
|
|
|
RoadBits pieces = Extract<RoadBits, 0>(p1);
|
|
|
|
|
|
|
|
return RemoveRoad(tile, flags, pieces, rt, true);
|
|
|
|
}
|
|
|
|
|
2007-09-26 16:12:43 +00:00
|
|
|
/**
|
|
|
|
* Calculate the costs for roads on slopes
|
|
|
|
* Aside modify the RoadBits to fit on the slopes
|
|
|
|
*
|
|
|
|
* @note The RoadBits are modified too!
|
|
|
|
* @param tileh The current slope
|
|
|
|
* @param pieces The RoadBits we want to add
|
2008-03-27 14:26:31 +00:00
|
|
|
* @param existing The existent RoadBits of the current type
|
|
|
|
* @param other The other existent RoadBits
|
2007-09-26 16:12:43 +00:00
|
|
|
* @return The costs for these RoadBits on this slope
|
|
|
|
*/
|
2008-04-04 18:41:16 +00:00
|
|
|
static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existing, RoadBits other)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-03-27 14:26:31 +00:00
|
|
|
/* Remove already build pieces */
|
|
|
|
CLRBITS(*pieces, existing);
|
|
|
|
|
|
|
|
/* If we can't build anything stop here */
|
|
|
|
if (*pieces == ROAD_NONE) return CMD_ERROR;
|
|
|
|
|
|
|
|
/* All RoadBit combos are valid on flat land */
|
|
|
|
if (tileh == SLOPE_FLAT) return CommandCost();
|
|
|
|
|
2008-03-25 18:59:25 +00:00
|
|
|
/* Proceed steep Slopes first to reduce lookup table size */
|
2006-08-10 14:44:32 +00:00
|
|
|
if (IsSteepSlope(tileh)) {
|
2007-09-26 16:12:43 +00:00
|
|
|
/* Force straight roads. */
|
|
|
|
*pieces |= MirrorRoadBits(*pieces);
|
2007-07-26 11:19:03 +00:00
|
|
|
|
2008-03-27 14:26:31 +00:00
|
|
|
/* Use existing as all existing since only straight
|
|
|
|
* roads are allowed here. */
|
|
|
|
existing |= other;
|
|
|
|
|
|
|
|
if ((existing == ROAD_NONE || existing == *pieces) && IsStraightRoad(*pieces)) {
|
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
|
2006-08-10 14:44:32 +00:00
|
|
|
}
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2007-09-26 16:12:43 +00:00
|
|
|
|
2008-03-27 14:26:31 +00:00
|
|
|
/* Save the merge of all bits of the current type */
|
|
|
|
RoadBits type_bits = existing | *pieces;
|
2007-09-26 16:12:43 +00:00
|
|
|
|
2008-03-27 14:26:31 +00:00
|
|
|
/* Roads on slopes */
|
2008-03-27 14:46:27 +00:00
|
|
|
if (_patches.build_on_slopes && (_invalid_tileh_slopes_road[0][tileh] & (other | type_bits)) == ROAD_NONE) {
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-03-27 14:26:31 +00:00
|
|
|
/* If we add leveling we've got to pay for it */
|
|
|
|
if ((other | existing) == ROAD_NONE) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
|
2006-03-31 06:16:04 +00:00
|
|
|
|
2008-03-27 14:26:31 +00:00
|
|
|
return CommandCost();
|
2006-03-31 06:16:04 +00:00
|
|
|
}
|
|
|
|
|
2008-03-27 14:26:31 +00:00
|
|
|
/* Autocomplete uphill roads */
|
2007-09-26 16:12:43 +00:00
|
|
|
*pieces |= MirrorRoadBits(*pieces);
|
2008-03-27 14:26:31 +00:00
|
|
|
type_bits = existing | *pieces;
|
|
|
|
|
|
|
|
/* Uphill roads */
|
|
|
|
if (IsStraightRoad(type_bits) && (other == type_bits || other == ROAD_NONE) &&
|
|
|
|
(_invalid_tileh_slopes_road[1][tileh] & (other | type_bits)) == ROAD_NONE) {
|
2007-07-26 11:19:03 +00:00
|
|
|
|
2008-03-27 14:26:31 +00:00
|
|
|
/* Slopes with foundation ? */
|
|
|
|
if (IsSlopeWithOneCornerRaised(tileh)) {
|
|
|
|
|
|
|
|
/* Prevent build on slopes if it isn't allowed */
|
2008-03-27 14:46:27 +00:00
|
|
|
if (_patches.build_on_slopes) {
|
2008-03-27 14:26:31 +00:00
|
|
|
|
|
|
|
/* If we add foundation we've got to pay for it */
|
|
|
|
if ((other | existing) == ROAD_NONE) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
|
|
|
|
|
|
|
|
return CommandCost();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (CountBits(existing) == 1) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
|
|
|
|
return CommandCost();
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/** Build a piece of road.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile where to build road
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2007-02-24 09:42:39 +00:00
|
|
|
* @param p1 bit 0..3 road pieces to build (RoadBits)
|
2007-05-20 19:14:08 +00:00
|
|
|
* bit 4..5 road type
|
2007-05-31 15:15:00 +00:00
|
|
|
* bit 6..7 disallowed directions to toggle
|
2005-05-09 22:33:00 +00:00
|
|
|
* @param p2 the town that is building the road (0 if not applicable)
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-01-09 16:55:48 +00:00
|
|
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
2008-04-04 18:41:16 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
RoadBits existing = ROAD_NONE;
|
2008-03-27 14:26:31 +00:00
|
|
|
RoadBits other_bits = ROAD_NONE;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
|
|
|
|
* if a non-player is building the road */
|
2007-02-24 09:42:39 +00:00
|
|
|
if ((IsValidPlayer(_current_player) && p2 != 0) || (_current_player == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR;
|
|
|
|
|
|
|
|
RoadBits pieces = Extract<RoadBits, 0>(p1);
|
2005-05-09 22:33:00 +00:00
|
|
|
|
2008-03-12 18:10:45 +00:00
|
|
|
/* do not allow building 'zero' road bits, code wouldn't handle it */
|
|
|
|
if (pieces == ROAD_NONE) return CMD_ERROR;
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadType rt = (RoadType)GB(p1, 4, 2);
|
2007-11-11 12:34:44 +00:00
|
|
|
if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
|
2007-05-20 19:14:08 +00:00
|
|
|
|
2007-05-31 15:15:00 +00:00
|
|
|
DisallowedRoadDirections toggle_drd = (DisallowedRoadDirections)GB(p1, 6, 2);
|
|
|
|
|
2008-03-25 18:59:25 +00:00
|
|
|
Slope tileh = GetTileSlope(tile, NULL);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-03 15:18:12 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2007-07-29 23:42:59 +00:00
|
|
|
case MP_ROAD:
|
2006-05-09 08:25:31 +00:00
|
|
|
switch (GetRoadTileType(tile)) {
|
2007-05-31 15:15:00 +00:00
|
|
|
case ROAD_TILE_NORMAL: {
|
2006-06-19 17:22:57 +00:00
|
|
|
if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
|
2007-05-30 20:13:58 +00:00
|
|
|
|
2008-03-27 14:26:31 +00:00
|
|
|
other_bits = GetOtherRoadBits(tile, rt);
|
2008-02-14 15:59:16 +00:00
|
|
|
if (!HasTileRoadType(tile, rt)) break;
|
2006-06-19 17:22:57 +00:00
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
existing = GetRoadBits(tile, rt);
|
2008-03-25 18:59:25 +00:00
|
|
|
bool crossing = !IsStraightRoad(existing | pieces);
|
2007-05-31 18:12:35 +00:00
|
|
|
if (rt != ROADTYPE_TRAM && (GetDisallowedRoadDirections(tile) != DRD_NONE || toggle_drd != DRD_NONE) && crossing) {
|
2007-05-31 15:15:00 +00:00
|
|
|
/* Junctions cannot be one-way */
|
|
|
|
return_cmd_error(STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
|
|
|
|
}
|
2006-03-06 13:11:08 +00:00
|
|
|
if ((existing & pieces) == pieces) {
|
2007-05-31 15:15:00 +00:00
|
|
|
/* We only want to set the (dis)allowed road directions */
|
|
|
|
if (toggle_drd != DRD_NONE && rt != ROADTYPE_TRAM && GetRoadOwner(tile, ROADTYPE_ROAD) == _current_player) {
|
|
|
|
if (crossing) return_cmd_error(STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
|
|
|
|
|
2008-02-18 22:12:27 +00:00
|
|
|
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
|
|
|
|
2007-05-31 15:15:00 +00:00
|
|
|
/* Ignore half built tiles */
|
2008-03-25 18:59:25 +00:00
|
|
|
if (flags & DC_EXEC && rt != ROADTYPE_TRAM && IsStraightRoad(existing)) {
|
2007-05-31 15:15:00 +00:00
|
|
|
SetDisallowedRoadDirections(tile, GetDisallowedRoadDirections(tile) ^ toggle_drd);
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2007-05-31 15:15:00 +00:00
|
|
|
}
|
2006-02-23 07:26:49 +00:00
|
|
|
return_cmd_error(STR_1007_ALREADY_BUILT);
|
|
|
|
}
|
2007-05-31 15:15:00 +00:00
|
|
|
} break;
|
2006-02-23 07:26:49 +00:00
|
|
|
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_CROSSING:
|
2008-02-14 15:59:16 +00:00
|
|
|
if (HasTileRoadType(tile, rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
|
2008-03-27 14:26:31 +00:00
|
|
|
other_bits = GetCrossingRoadBits(tile);
|
|
|
|
if (pieces & ComplementRoadBits(other_bits)) goto do_clear;
|
2007-05-20 19:14:08 +00:00
|
|
|
break;
|
2006-02-23 07:26:49 +00:00
|
|
|
|
2006-02-23 08:20:28 +00:00
|
|
|
default:
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_DEPOT:
|
2006-02-23 07:26:49 +00:00
|
|
|
goto do_clear;
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-21 18:07:35 +00:00
|
|
|
case MP_RAILWAY: {
|
2006-04-23 13:48:16 +00:00
|
|
|
if (IsSteepSlope(tileh)) {
|
2006-02-21 18:07:35 +00:00
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
|
|
|
}
|
2004-08-10 18:35:43 +00:00
|
|
|
|
2006-03-01 15:03:47 +00:00
|
|
|
/* Level crossings may only be built on these slopes */
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh)) {
|
2006-02-21 18:07:35 +00:00
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-05-09 08:17:33 +00:00
|
|
|
if (GetRailTileType(tile) != RAIL_TILE_NORMAL) goto do_clear;
|
2008-04-04 18:41:16 +00:00
|
|
|
|
|
|
|
Axis roaddir;
|
2006-03-19 13:48:08 +00:00
|
|
|
switch (GetTrackBits(tile)) {
|
|
|
|
case TRACK_BIT_X:
|
|
|
|
if (pieces & ROAD_X) goto do_clear;
|
|
|
|
roaddir = AXIS_Y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRACK_BIT_Y:
|
|
|
|
if (pieces & ROAD_Y) goto do_clear;
|
|
|
|
roaddir = AXIS_X;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: goto do_clear;
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
|
|
|
|
2007-04-01 11:11:49 +00:00
|
|
|
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
2006-03-31 06:16:04 +00:00
|
|
|
|
2006-02-21 18:07:35 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2007-01-10 18:56:51 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
|
2007-05-26 07:58:49 +00:00
|
|
|
/* Always add road to the roadtypes (can't draw without it) */
|
|
|
|
MakeRoadCrossing(tile, _current_player, _current_player, _current_player, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2);
|
2008-01-17 20:41:33 +00:00
|
|
|
UpdateLevelCrossing(tile, false);
|
2006-03-01 06:39:04 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
2008-01-09 16:55:48 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_road * (rt == ROADTYPE_ROAD ? 2 : 4));
|
2006-02-13 21:15:00 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-05-24 09:31:09 +00:00
|
|
|
case MP_STATION:
|
|
|
|
if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
|
2008-02-14 15:59:16 +00:00
|
|
|
if (HasTileRoadType(tile, rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
|
2007-05-24 09:31:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_TUNNELBRIDGE:
|
2008-01-23 14:51:36 +00:00
|
|
|
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
|
2008-02-14 15:59:16 +00:00
|
|
|
if (HasTileRoadType(tile, rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
|
2008-01-23 14:51:36 +00:00
|
|
|
/* Don't allow adding roadtype to the bridge/tunnel when vehicles are already driving on it */
|
|
|
|
if (GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL) return CMD_ERROR;
|
|
|
|
break;
|
2007-05-24 09:31:09 +00:00
|
|
|
|
2008-04-04 18:41:16 +00:00
|
|
|
default: {
|
2004-08-09 17:04:08 +00:00
|
|
|
do_clear:;
|
2008-04-04 18:41:16 +00:00
|
|
|
CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2006-03-31 06:16:04 +00:00
|
|
|
if (CmdFailed(ret)) return ret;
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(ret);
|
2008-04-04 18:41:16 +00:00
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-03-27 14:26:31 +00:00
|
|
|
if (other_bits != pieces) {
|
2007-05-26 22:19:04 +00:00
|
|
|
/* Check the foundation/slopes when adding road/tram bits */
|
2008-04-04 18:41:16 +00:00
|
|
|
CommandCost ret = CheckRoadSlope(tileh, &pieces, existing, other_bits);
|
2007-05-26 22:19:04 +00:00
|
|
|
/* Return an error if we need to build a foundation (ret != 0) but the
|
|
|
|
* current patch-setting is turned off (or stupid AI@work) */
|
2008-03-27 14:46:27 +00:00
|
|
|
if (CmdFailed(ret) || (ret.GetCost() != 0 && !_patches.build_on_slopes)) {
|
2007-05-26 22:19:04 +00:00
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(ret);
|
2007-05-26 22:19:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-29 23:42:59 +00:00
|
|
|
if (IsTileType(tile, MP_ROAD)) {
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Don't put the pieces that already exist */
|
2006-03-06 13:11:08 +00:00
|
|
|
pieces &= ComplementRoadBits(existing);
|
2008-01-23 00:36:48 +00:00
|
|
|
|
|
|
|
/* Check if new road bits will have the same foundation as other existing road types */
|
2008-02-14 15:59:16 +00:00
|
|
|
if (IsNormalRoad(tile)) {
|
2008-01-23 00:36:48 +00:00
|
|
|
Slope slope = GetTileSlope(tile, NULL);
|
|
|
|
Foundation found_new = GetRoadFoundation(slope, pieces | existing);
|
|
|
|
|
|
|
|
/* Test if all other roadtypes can be built at that foundation */
|
|
|
|
for (RoadType rtest = ROADTYPE_ROAD; rtest < ROADTYPE_END; rtest++) {
|
|
|
|
if (rtest != rt) { // check only other road types
|
|
|
|
RoadBits bits = GetRoadBits(tile, rtest);
|
|
|
|
/* do not check if there are not road bits of given type */
|
|
|
|
if (bits != ROAD_NONE && GetRoadFoundation(slope, bits) != found_new) {
|
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-02-18 22:12:27 +00:00
|
|
|
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
|
|
|
|
2007-11-04 22:47:34 +00:00
|
|
|
cost.AddCost(CountBits(pieces) * _price.build_road);
|
2007-05-24 09:31:09 +00:00
|
|
|
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
|
|
|
/* Pay for *every* tile of the bridge or tunnel */
|
2008-01-23 22:34:04 +00:00
|
|
|
cost.MultiplyCost(GetTunnelBridgeLength(GetOtherTunnelBridgeEnd(tile), tile) + 2);
|
2007-05-24 09:31:09 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2007-05-24 09:31:09 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2007-07-29 23:42:59 +00:00
|
|
|
case MP_ROAD: {
|
2007-05-24 09:31:09 +00:00
|
|
|
RoadTileType rtt = GetRoadTileType(tile);
|
|
|
|
if (existing == ROAD_NONE || rtt == ROAD_TILE_CROSSING) {
|
|
|
|
SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
|
|
|
|
SetRoadOwner(tile, rt, _current_player);
|
2007-06-19 17:27:59 +00:00
|
|
|
if (_current_player == OWNER_TOWN && rt == ROADTYPE_ROAD) SetTownIndex(tile, p2);
|
2007-05-24 09:31:09 +00:00
|
|
|
}
|
|
|
|
if (rtt != ROAD_TILE_CROSSING) SetRoadBits(tile, existing | pieces, rt);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case MP_TUNNELBRIDGE: {
|
2008-01-04 19:45:29 +00:00
|
|
|
TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
|
2007-05-24 09:31:09 +00:00
|
|
|
|
|
|
|
SetRoadTypes(other_end, GetRoadTypes(other_end) | RoadTypeToRoadTypes(rt));
|
2007-05-20 19:14:08 +00:00
|
|
|
SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
|
2007-05-24 09:31:09 +00:00
|
|
|
|
|
|
|
/* Mark tiles diry that have been repaved */
|
|
|
|
MarkTileDirtyByTile(other_end);
|
2007-05-26 22:01:49 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2007-05-24 09:31:09 +00:00
|
|
|
if (IsBridge(tile)) {
|
2007-12-16 15:38:51 +00:00
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
|
2007-05-24 09:31:09 +00:00
|
|
|
|
2007-05-26 21:45:16 +00:00
|
|
|
for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t);
|
2007-05-24 09:31:09 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case MP_STATION:
|
|
|
|
SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, _current_player, _current_player, _current_player);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-02-14 15:59:16 +00:00
|
|
|
if (rt != ROADTYPE_TRAM && IsNormalRoadTile(tile)) {
|
2007-05-31 15:15:00 +00:00
|
|
|
existing |= pieces;
|
2008-03-25 18:59:25 +00:00
|
|
|
SetDisallowedRoadDirections(tile, IsStraightRoad(existing) ?
|
2007-05-31 15:15:00 +00:00
|
|
|
GetDisallowedRoadDirections(tile) ^ toggle_drd : DRD_NONE);
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/** Build a long piece of road.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param end_tile end tile of drag
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-09 22:33:00 +00:00
|
|
|
* @param p1 start tile of drag
|
|
|
|
* @param p2 various bitstuffed elements
|
|
|
|
* - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
|
|
|
|
* - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
|
|
|
|
* - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
|
2007-05-20 22:04:24 +00:00
|
|
|
* - p2 = (bit 3 + 4) - road type
|
2007-05-31 15:15:00 +00:00
|
|
|
* - p2 = (bit 5) - set road direction
|
2005-05-09 22:33:00 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-04-04 18:41:16 +00:00
|
|
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
2007-05-26 20:52:23 +00:00
|
|
|
bool had_bridge = false;
|
2007-08-09 05:25:33 +00:00
|
|
|
bool had_tunnel = false;
|
2007-05-31 15:15:00 +00:00
|
|
|
bool had_success = false;
|
|
|
|
DisallowedRoadDirections drd = DRD_NORTHBOUND;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-02-18 22:12:27 +00:00
|
|
|
_error_message = INVALID_STRING_ID;
|
|
|
|
|
2006-01-30 17:18:45 +00:00
|
|
|
if (p1 >= MapSize()) return CMD_ERROR;
|
2005-05-09 22:33:00 +00:00
|
|
|
|
2008-04-04 18:41:16 +00:00
|
|
|
TileIndex start_tile = p1;
|
2007-05-20 22:04:24 +00:00
|
|
|
RoadType rt = (RoadType)GB(p2, 3, 2);
|
2007-11-11 12:34:44 +00:00
|
|
|
if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/* Only drag in X or Y direction dictated by the direction variable */
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!HasBit(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
|
|
|
|
if (HasBit(p2, 2) && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
|
2005-05-09 22:33:00 +00:00
|
|
|
|
|
|
|
/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */
|
2007-11-19 21:02:30 +00:00
|
|
|
if (start_tile > end_tile || (start_tile == end_tile && HasBit(p2, 0))) {
|
2005-05-09 22:33:00 +00:00
|
|
|
TileIndex t = start_tile;
|
|
|
|
start_tile = end_tile;
|
|
|
|
end_tile = t;
|
2007-11-24 10:38:43 +00:00
|
|
|
p2 ^= IsInsideMM(p2 & 3, 1, 3) ? 3 : 0;
|
2007-05-31 15:15:00 +00:00
|
|
|
drd = DRD_SOUTHBOUND;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-05-31 15:15:00 +00:00
|
|
|
/* On the X-axis, we have to swap the initial bits, so they
|
|
|
|
* will be interpreted correctly in the GTTS. Futhermore
|
|
|
|
* when you just 'click' on one tile to build them. */
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(p2, 2) == (start_tile == end_tile && HasBit(p2, 0) == HasBit(p2, 1))) drd ^= DRD_BOTH;
|
2007-05-31 15:15:00 +00:00
|
|
|
/* No disallowed direction bits have to be toggled */
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!HasBit(p2, 5)) drd = DRD_NONE;
|
2007-05-31 15:15:00 +00:00
|
|
|
|
2008-04-04 18:41:16 +00:00
|
|
|
TileIndex tile = start_tile;
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Start tile is the small number. */
|
2005-05-09 22:33:00 +00:00
|
|
|
for (;;) {
|
2007-11-19 21:02:30 +00:00
|
|
|
RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X;
|
2006-02-28 13:18:14 +00:00
|
|
|
|
2007-11-19 21:02:30 +00:00
|
|
|
if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE;
|
|
|
|
if (tile == start_tile && HasBit(p2, 0)) bits &= ROAD_SE | ROAD_SW;
|
2005-05-09 22:33:00 +00:00
|
|
|
|
2008-04-04 18:41:16 +00:00
|
|
|
CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
|
2005-05-09 22:33:00 +00:00
|
|
|
if (CmdFailed(ret)) {
|
|
|
|
if (_error_message != STR_1007_ALREADY_BUILT) return CMD_ERROR;
|
2005-10-23 13:04:44 +00:00
|
|
|
} else {
|
2007-05-31 15:15:00 +00:00
|
|
|
had_success = true;
|
2007-08-09 05:25:33 +00:00
|
|
|
/* Only pay for the upgrade on one side of the bridges and tunnels */
|
|
|
|
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
|
|
|
if (IsBridge(tile)) {
|
2007-12-16 15:38:51 +00:00
|
|
|
if ((!had_bridge || GetTunnelBridgeDirection(tile) == DIAGDIR_SE || GetTunnelBridgeDirection(tile) == DIAGDIR_SW)) {
|
2007-08-09 05:25:33 +00:00
|
|
|
cost.AddCost(ret);
|
|
|
|
}
|
|
|
|
had_bridge = true;
|
2008-01-23 14:51:36 +00:00
|
|
|
} else { // IsTunnel(tile)
|
2007-12-16 15:38:51 +00:00
|
|
|
if ((!had_tunnel || GetTunnelBridgeDirection(tile) == DIAGDIR_SE || GetTunnelBridgeDirection(tile) == DIAGDIR_SW)) {
|
2007-08-09 05:25:33 +00:00
|
|
|
cost.AddCost(ret);
|
|
|
|
}
|
|
|
|
had_tunnel = true;
|
2007-05-26 20:52:23 +00:00
|
|
|
}
|
|
|
|
} else {
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(ret);
|
2007-05-26 20:52:23 +00:00
|
|
|
}
|
2005-10-23 13:04:44 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
if (tile == end_tile) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-11-19 21:02:30 +00:00
|
|
|
tile += HasBit(p2, 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-05-31 15:15:00 +00:00
|
|
|
return !had_success ? CMD_ERROR : cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/** Remove a long piece of road.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param end_tile end tile of drag
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-09 22:33:00 +00:00
|
|
|
* @param p1 start tile of drag
|
|
|
|
* @param p2 various bitstuffed elements
|
|
|
|
* - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
|
|
|
|
* - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
|
|
|
|
* - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
|
2007-05-20 22:04:24 +00:00
|
|
|
* - p2 = (bit 3 + 4) - road type
|
2005-05-09 22:33:00 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-04-04 18:41:16 +00:00
|
|
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
2005-01-04 17:11:03 +00:00
|
|
|
|
2006-01-30 17:18:45 +00:00
|
|
|
if (p1 >= MapSize()) return CMD_ERROR;
|
2005-05-09 22:33:00 +00:00
|
|
|
|
2008-04-04 18:41:16 +00:00
|
|
|
TileIndex start_tile = p1;
|
2007-05-20 22:04:24 +00:00
|
|
|
RoadType rt = (RoadType)GB(p2, 3, 2);
|
|
|
|
if (!IsValidRoadType(rt)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/* Only drag in X or Y direction dictated by the direction variable */
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!HasBit(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
|
|
|
|
if (HasBit(p2, 2) && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
|
2005-05-09 22:33:00 +00:00
|
|
|
|
|
|
|
/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */
|
2007-11-19 21:02:30 +00:00
|
|
|
if (start_tile > end_tile || (start_tile == end_tile && HasBit(p2, 0))) {
|
2005-05-09 22:33:00 +00:00
|
|
|
TileIndex t = start_tile;
|
|
|
|
start_tile = end_tile;
|
|
|
|
end_tile = t;
|
2007-11-24 10:38:43 +00:00
|
|
|
p2 ^= IsInsideMM(p2 & 3, 1, 3) ? 3 : 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-04-04 18:41:16 +00:00
|
|
|
Money money = GetAvailableMoneyForCommand();
|
|
|
|
TileIndex tile = start_tile;
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Start tile is the small number. */
|
2005-05-09 22:33:00 +00:00
|
|
|
for (;;) {
|
2007-11-19 21:02:30 +00:00
|
|
|
RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X;
|
2006-02-28 13:18:14 +00:00
|
|
|
|
2007-11-19 21:02:30 +00:00
|
|
|
if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE;
|
|
|
|
if (tile == start_tile && HasBit(p2, 0)) bits &= ROAD_SE | ROAD_SW;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* try to remove the halves. */
|
2006-02-28 13:18:14 +00:00
|
|
|
if (bits != 0) {
|
2008-04-04 18:41:16 +00:00
|
|
|
CommandCost ret = RemoveRoad(tile, flags & ~DC_EXEC, bits, rt, true);
|
2007-08-14 17:05:33 +00:00
|
|
|
if (CmdSucceeded(ret)) {
|
|
|
|
if (flags & DC_EXEC) {
|
2008-01-09 16:55:48 +00:00
|
|
|
money -= ret.GetCost();
|
|
|
|
if (money < 0) {
|
2007-08-14 17:05:33 +00:00
|
|
|
_additional_cash_required = DoCommand(end_tile, start_tile, p2, flags & ~DC_EXEC, CMD_REMOVE_LONG_ROAD).GetCost();
|
|
|
|
return cost;
|
|
|
|
}
|
2008-01-28 12:40:31 +00:00
|
|
|
RemoveRoad(tile, flags, bits, rt, true);
|
2007-08-14 17:05:33 +00:00
|
|
|
}
|
|
|
|
cost.AddCost(ret);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
if (tile == end_tile) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-11-19 21:02:30 +00:00
|
|
|
tile += HasBit(p2, 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return (cost.GetCost() == 0) ? CMD_ERROR : cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/** Build a road depot.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile where to build the depot
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2007-02-24 09:42:39 +00:00
|
|
|
* @param p1 bit 0..1 entrance direction (DiagDirection)
|
2007-05-20 22:04:24 +00:00
|
|
|
* bit 2..3 road type
|
2005-05-09 22:33:00 +00:00
|
|
|
* @param p2 unused
|
2005-07-16 23:47:37 +00:00
|
|
|
*
|
|
|
|
* @todo When checking for the tile slope,
|
|
|
|
* distingush between "Flat land required" and "land sloped in wrong direction"
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-02-24 09:42:39 +00:00
|
|
|
DiagDirection dir = Extract<DiagDirection, 0>(p1);
|
2007-05-20 22:04:24 +00:00
|
|
|
RoadType rt = (RoadType)GB(p1, 2, 2);
|
|
|
|
|
2007-11-11 12:34:44 +00:00
|
|
|
if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
|
2005-05-09 22:33:00 +00:00
|
|
|
|
2008-04-04 18:41:16 +00:00
|
|
|
Slope tileh = GetTileSlope(tile, NULL);
|
2006-04-23 13:48:16 +00:00
|
|
|
if (tileh != SLOPE_FLAT && (
|
2005-10-23 13:04:44 +00:00
|
|
|
!_patches.build_on_slopes ||
|
2006-04-23 13:48:16 +00:00
|
|
|
IsSteepSlope(tileh) ||
|
2007-02-24 09:42:39 +00:00
|
|
|
!CanBuildDepotByTileh(dir, tileh)
|
2005-10-23 13:04:44 +00:00
|
|
|
)) {
|
|
|
|
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-04-04 18:41:16 +00:00
|
|
|
CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2005-05-09 22:33:00 +00:00
|
|
|
if (CmdFailed(cost)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
|
|
|
|
|
2007-08-02 22:33:53 +00:00
|
|
|
Depot *dep = new Depot(tile);
|
2005-10-23 13:04:44 +00:00
|
|
|
if (dep == NULL) return CMD_ERROR;
|
2007-08-02 22:33:53 +00:00
|
|
|
AutoPtrT<Depot> d_auto_delete = dep;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-09-11 09:55:19 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2004-08-09 17:04:08 +00:00
|
|
|
dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
MakeRoadDepot(tile, _current_player, dir, rt);
|
2006-03-01 06:39:04 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2007-08-02 22:33:53 +00:00
|
|
|
d_auto_delete.Detach();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
return cost.AddCost(_price.build_road_depot);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
static CommandCost RemoveRoadDepot(TileIndex tile, uint32 flags)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-04-04 18:41:16 +00:00
|
|
|
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-10-19 22:46:55 +00:00
|
|
|
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-08-02 22:33:53 +00:00
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
DoClearSquare(tile);
|
|
|
|
delete GetDepotByTile(tile);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-09 16:55:48 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_road_depot);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
static CommandCost ClearTile_Road(TileIndex tile, byte flags)
|
2005-06-24 12:38:35 +00:00
|
|
|
{
|
2006-05-09 08:25:31 +00:00
|
|
|
switch (GetRoadTileType(tile)) {
|
|
|
|
case ROAD_TILE_NORMAL: {
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadBits b = GetAllRoadBits(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-13 14:48:47 +00:00
|
|
|
/* Clear the road if only one piece is on the tile OR the AI tries
|
|
|
|
* to clear town road OR we are not using the DC_AUTO flag */
|
2007-11-04 22:47:34 +00:00
|
|
|
if ((CountBits(b) == 1 && GetRoadBits(tile, ROADTYPE_TRAM) == ROAD_NONE) ||
|
2007-01-13 14:48:47 +00:00
|
|
|
((flags & DC_AI_BUILDING) && IsTileOwner(tile, OWNER_TOWN)) ||
|
|
|
|
!(flags & DC_AUTO)
|
|
|
|
) {
|
2007-05-24 09:31:09 +00:00
|
|
|
RoadTypes rts = GetRoadTypes(tile);
|
2008-01-09 16:55:48 +00:00
|
|
|
CommandCost ret(EXPENSES_CONSTRUCTION);
|
2007-05-24 09:31:09 +00:00
|
|
|
for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(rts, rt)) {
|
2008-01-28 12:40:31 +00:00
|
|
|
CommandCost tmp_ret = RemoveRoad(tile, flags, GetRoadBits(tile, rt), rt, true);
|
2007-05-24 09:31:09 +00:00
|
|
|
if (CmdFailed(tmp_ret)) return tmp_ret;
|
2007-06-18 19:53:50 +00:00
|
|
|
ret.AddCost(tmp_ret);
|
2007-05-24 09:31:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
2007-01-13 14:48:47 +00:00
|
|
|
return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
|
2007-01-13 15:55:22 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_CROSSING: {
|
2007-06-07 08:58:21 +00:00
|
|
|
RoadTypes rts = GetRoadTypes(tile);
|
2008-01-09 16:55:48 +00:00
|
|
|
CommandCost ret(EXPENSES_CONSTRUCTION);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2006-02-23 08:20:28 +00:00
|
|
|
if (flags & DC_AUTO) return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
|
2006-02-21 18:07:35 +00:00
|
|
|
|
2007-06-07 08:58:21 +00:00
|
|
|
/* Must iterate over the roadtypes in a reverse manner because
|
|
|
|
* tram tracks must be removed before the road bits. */
|
|
|
|
for (RoadType rt = ROADTYPE_HWAY; rt >= ROADTYPE_ROAD; rt--) {
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(rts, rt)) {
|
2008-01-28 12:40:31 +00:00
|
|
|
CommandCost tmp_ret = RemoveRoad(tile, flags, GetCrossingRoadBits(tile), rt, false);
|
2007-06-07 08:58:21 +00:00
|
|
|
if (CmdFailed(tmp_ret)) return tmp_ret;
|
2007-06-18 19:53:50 +00:00
|
|
|
ret.AddCost(tmp_ret);
|
2007-06-07 08:58:21 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-21 18:07:35 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2006-04-10 07:15:58 +00:00
|
|
|
DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
|
|
|
return ret;
|
2004-09-11 09:55:19 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-23 08:20:28 +00:00
|
|
|
default:
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_DEPOT:
|
2006-02-21 18:07:35 +00:00
|
|
|
if (flags & DC_AUTO) {
|
|
|
|
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
|
|
|
|
}
|
|
|
|
return RemoveRoadDepot(tile, flags);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct DrawRoadTileStruct {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 image;
|
|
|
|
byte subcoord_x;
|
|
|
|
byte subcoord_y;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
#include "table/road_land.h"
|
|
|
|
|
2008-03-25 18:59:25 +00:00
|
|
|
/**
|
|
|
|
* Get the foundationtype of a RoadBits Slope combination
|
|
|
|
*
|
|
|
|
* @param tileh The Slope part
|
|
|
|
* @param bits The RoadBits part
|
|
|
|
* @return The resulting Foundation
|
|
|
|
*/
|
2007-07-26 16:51:10 +00:00
|
|
|
Foundation GetRoadFoundation(Slope tileh, RoadBits bits)
|
2005-10-22 06:39:32 +00:00
|
|
|
{
|
2008-03-25 18:59:25 +00:00
|
|
|
/* Flat land and land without a road doesn't require a foundation */
|
|
|
|
if (tileh == SLOPE_FLAT || bits == ROAD_NONE) return FOUNDATION_NONE;
|
|
|
|
|
2007-07-26 16:51:10 +00:00
|
|
|
if (!IsSteepSlope(tileh)) {
|
2008-03-27 14:26:31 +00:00
|
|
|
/* Leveled RoadBits on a slope */
|
|
|
|
if ((_invalid_tileh_slopes_road[0][tileh] & bits) == ROAD_NONE) return FOUNDATION_LEVELED;
|
|
|
|
|
|
|
|
/* Straight roads without foundation on a slope */
|
|
|
|
if (!IsSlopeWithOneCornerRaised(tileh) &&
|
|
|
|
(_invalid_tileh_slopes_road[1][tileh] & bits) == ROAD_NONE)
|
|
|
|
return FOUNDATION_NONE;
|
2006-08-10 14:44:32 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-03-27 14:26:31 +00:00
|
|
|
/* Roads on steep Slopes or on Slopes with one corner raised */
|
2007-07-26 16:51:10 +00:00
|
|
|
return (bits == ROAD_X ? FOUNDATION_INCLINED_X : FOUNDATION_INCLINED_Y);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const byte _road_sloped_sprites[14] = {
|
|
|
|
0, 0, 2, 0,
|
|
|
|
0, 1, 0, 0,
|
|
|
|
3, 0, 0, 0,
|
|
|
|
0, 0
|
|
|
|
};
|
|
|
|
|
2007-04-27 21:35:02 +00:00
|
|
|
/**
|
|
|
|
* Whether to draw unpaved roads regardless of the town zone.
|
|
|
|
* By default, OpenTTD always draws roads as unpaved if they are on a desert
|
|
|
|
* tile or above the snowline. Newgrf files, however, can set a bit that allows
|
|
|
|
* paved roads to be built on desert tiles as they would be on grassy tiles.
|
|
|
|
*
|
|
|
|
* @param tile The tile the road is on
|
|
|
|
* @param roadside What sort of road this is
|
|
|
|
* @return True if the road should be drawn unpaved regardless of the roadside.
|
|
|
|
*/
|
|
|
|
static bool AlwaysDrawUnpavedRoads(TileIndex tile, Roadside roadside)
|
|
|
|
{
|
|
|
|
return (IsOnSnow(tile) &&
|
|
|
|
!(_opt.landscape == LT_TROPIC && HasGrfMiscBit(GMB_DESERT_PAVED_ROADS) &&
|
|
|
|
roadside != ROADSIDE_BARREN && roadside != ROADSIDE_GRASS && roadside != ROADSIDE_GRASS_ROAD_WORKS));
|
|
|
|
}
|
|
|
|
|
2007-05-25 22:07:40 +00:00
|
|
|
/**
|
|
|
|
* Draws the catenary for the given tile
|
|
|
|
* @param ti information about the tile (slopes, height etc)
|
|
|
|
* @param tram the roadbits for the tram
|
|
|
|
*/
|
2008-04-04 18:41:16 +00:00
|
|
|
void DrawTramCatenary(const TileInfo *ti, RoadBits tram)
|
2007-05-25 22:07:40 +00:00
|
|
|
{
|
2008-04-03 19:55:40 +00:00
|
|
|
/* Do not draw catenary if it is invisible */
|
|
|
|
if (IsInvisibilitySet(TO_CATENARY)) return;
|
|
|
|
|
2007-05-25 22:07:40 +00:00
|
|
|
/* Don't draw the catenary under a low bridge */
|
2008-02-10 15:53:26 +00:00
|
|
|
if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !IsTransparencySet(TO_CATENARY)) {
|
2007-05-25 22:07:40 +00:00
|
|
|
uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
|
|
|
|
|
2007-05-26 10:40:34 +00:00
|
|
|
if (height <= GetTileMaxZ(ti->tile) + TILE_HEIGHT) return;
|
2007-05-25 22:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SpriteID front;
|
|
|
|
SpriteID back;
|
|
|
|
|
|
|
|
if (ti->tileh != SLOPE_FLAT) {
|
|
|
|
back = SPR_TRAMWAY_BACK_WIRES_SLOPED + _road_sloped_sprites[ti->tileh - 1];
|
|
|
|
front = SPR_TRAMWAY_FRONT_WIRES_SLOPED + _road_sloped_sprites[ti->tileh - 1];
|
|
|
|
} else {
|
|
|
|
back = SPR_TRAMWAY_BASE + _road_backpole_sprites_1[tram];
|
|
|
|
front = SPR_TRAMWAY_BASE + _road_frontwire_sprites_1[tram];
|
|
|
|
}
|
|
|
|
|
2008-02-10 15:53:26 +00:00
|
|
|
AddSortableSpriteToDraw(back, PAL_NONE, ti->x, ti->y, 16, 16, TILE_HEIGHT + BB_HEIGHT_UNDER_BRIDGE, ti->z, IsTransparencySet(TO_CATENARY));
|
|
|
|
AddSortableSpriteToDraw(front, PAL_NONE, ti->x, ti->y, 16, 16, TILE_HEIGHT + BB_HEIGHT_UNDER_BRIDGE, ti->z, IsTransparencySet(TO_CATENARY));
|
2007-05-25 22:07:40 +00:00
|
|
|
}
|
|
|
|
|
2007-05-31 15:15:00 +00:00
|
|
|
/**
|
|
|
|
* Draws details on/around the road
|
|
|
|
* @param img the sprite to draw
|
|
|
|
* @param ti the tile to draw on
|
|
|
|
* @param dx the offset from the top of the BB of the tile
|
|
|
|
* @param dy the offset from the top of the BB of the tile
|
|
|
|
* @param h the height of the sprite to draw
|
|
|
|
*/
|
2008-04-04 18:41:16 +00:00
|
|
|
static void DrawRoadDetail(SpriteID img, const TileInfo *ti, int dx, int dy, int h)
|
2007-05-31 15:15:00 +00:00
|
|
|
{
|
|
|
|
int x = ti->x | dx;
|
|
|
|
int y = ti->y | dy;
|
|
|
|
byte z = ti->z;
|
|
|
|
if (ti->tileh != SLOPE_FLAT) z = GetSlopeZ(x, y);
|
|
|
|
AddSortableSpriteToDraw(img, PAL_NONE, x, y, 2, 2, h, z);
|
|
|
|
}
|
|
|
|
|
2005-09-29 19:59:57 +00:00
|
|
|
/**
|
|
|
|
* Draw ground sprite and road pieces
|
|
|
|
* @param ti TileInfo
|
|
|
|
*/
|
2008-04-04 18:41:16 +00:00
|
|
|
static void DrawRoadBits(TileInfo *ti)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadBits road = GetRoadBits(ti->tile, ROADTYPE_ROAD);
|
2007-05-25 22:07:40 +00:00
|
|
|
RoadBits tram = GetRoadBits(ti->tile, ROADTYPE_TRAM);
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID image = 0;
|
|
|
|
SpriteID pal = PAL_NONE;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT) {
|
2007-07-26 16:51:10 +00:00
|
|
|
DrawFoundation(ti, GetRoadFoundation(ti->tileh, road | tram));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* DrawFoundation() modifies ti.
|
|
|
|
* Default sloped sprites.. */
|
2006-04-23 13:48:16 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F;
|
2005-09-29 19:59:57 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-05-25 22:07:40 +00:00
|
|
|
if (image == 0) image = _road_tile_sprites_1[road != ROAD_NONE ? road : tram];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-04 18:41:16 +00:00
|
|
|
Roadside roadside = GetRoadside(ti->tile);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-04-27 21:35:02 +00:00
|
|
|
if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) {
|
2005-09-29 19:59:57 +00:00
|
|
|
image += 19;
|
2006-06-19 20:13:50 +00:00
|
|
|
} else {
|
|
|
|
switch (roadside) {
|
2007-01-14 19:57:49 +00:00
|
|
|
case ROADSIDE_BARREN: pal = PALETTE_TO_BARE_LAND; break;
|
2006-06-19 20:13:50 +00:00
|
|
|
case ROADSIDE_GRASS: break;
|
|
|
|
case ROADSIDE_GRASS_ROAD_WORKS: break;
|
|
|
|
default: image -= 19; break; // Paved
|
|
|
|
}
|
2005-09-29 19:59:57 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(image, pal);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-05-25 22:07:40 +00:00
|
|
|
/* For tram we overlay the road graphics with either tram tracks only
|
|
|
|
* (when there is actual road beneath the trams) or with tram tracks
|
|
|
|
* and some dirts which hides the road graphics */
|
|
|
|
if (tram != ROAD_NONE) {
|
|
|
|
if (ti->tileh != SLOPE_FLAT) {
|
|
|
|
image = _road_sloped_sprites[ti->tileh - 1] + SPR_TRAMWAY_SLOPED_OFFSET;
|
|
|
|
} else {
|
|
|
|
image = _road_tile_sprites_1[tram] - SPR_ROAD_Y;
|
|
|
|
}
|
|
|
|
image += (road == ROAD_NONE) ? SPR_TRAMWAY_TRAM : SPR_TRAMWAY_OVERLAY;
|
|
|
|
DrawGroundSprite(image, pal);
|
|
|
|
}
|
|
|
|
|
2007-06-19 15:56:03 +00:00
|
|
|
if (road != ROAD_NONE) {
|
|
|
|
DisallowedRoadDirections drd = GetDisallowedRoadDirections(ti->tile);
|
|
|
|
if (drd != DRD_NONE) {
|
|
|
|
DrawRoadDetail(SPR_ONEWAY_BASE + drd - 1 + ((road == ROAD_X) ? 0 : 3), ti, 8, 8, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-03 13:35:19 +00:00
|
|
|
if (HasRoadWorks(ti->tile)) {
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Road works */
|
2007-05-25 22:07:40 +00:00
|
|
|
DrawGroundSprite((road | tram) & ROAD_X ? SPR_EXCAVATION_X : SPR_EXCAVATION_Y, PAL_NONE);
|
2005-09-29 19:59:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-05-25 22:07:40 +00:00
|
|
|
if (tram != ROAD_NONE) DrawTramCatenary(ti, tram);
|
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Return if full detail is disabled, or we are zoomed fully out. */
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!HasBit(_display_opt, DO_FULL_DETAIL) || _cur_dpi->zoom > ZOOM_LVL_DETAIL) return;
|
2006-11-22 18:16:50 +00:00
|
|
|
|
2008-02-17 21:27:44 +00:00
|
|
|
/* Do not draw details (street lights, trees) under low bridge */
|
|
|
|
if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && (roadside == ROADSIDE_TREES || roadside == ROADSIDE_STREET_LIGHTS)) {
|
|
|
|
uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
|
|
|
|
uint minz = GetTileMaxZ(ti->tile) + 2 * TILE_HEIGHT;
|
|
|
|
|
|
|
|
if (roadside == ROADSIDE_TREES) minz += TILE_HEIGHT;
|
|
|
|
|
|
|
|
if (height < minz) return;
|
|
|
|
}
|
|
|
|
|
2008-02-27 15:35:24 +00:00
|
|
|
/* If there are no road bits, return, as there is nothing left to do */
|
|
|
|
if (CountBits(road) < 2) return;
|
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Draw extra details. */
|
2008-04-04 18:41:16 +00:00
|
|
|
for (const DrawRoadTileStruct *drts = _road_display_table[roadside][road | tram]; drts->image != 0; drts++) {
|
2007-05-31 15:15:00 +00:00
|
|
|
DrawRoadDetail(drts->image, ti, drts->subcoord_x, drts->subcoord_y, 0x10);
|
2005-09-29 19:59:57 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-09-29 19:59:57 +00:00
|
|
|
static void DrawTile_Road(TileInfo *ti)
|
|
|
|
{
|
2006-05-09 08:25:31 +00:00
|
|
|
switch (GetRoadTileType(ti->tile)) {
|
|
|
|
case ROAD_TILE_NORMAL:
|
2006-06-28 06:10:20 +00:00
|
|
|
DrawRoadBits(ti);
|
2006-02-21 18:07:35 +00:00
|
|
|
break;
|
|
|
|
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_CROSSING: {
|
2007-07-26 16:51:10 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
|
2004-08-10 18:35:43 +00:00
|
|
|
|
2008-04-04 18:41:16 +00:00
|
|
|
SpriteID image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.crossing;
|
|
|
|
SpriteID pal = PAL_NONE;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-19 17:15:33 +00:00
|
|
|
if (GetCrossingRoadAxis(ti->tile) == AXIS_X) image++;
|
2006-03-24 15:24:16 +00:00
|
|
|
if (IsCrossingBarred(ti->tile)) image += 2;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-04 18:41:16 +00:00
|
|
|
Roadside roadside = GetRoadside(ti->tile);
|
|
|
|
|
2007-04-27 21:35:02 +00:00
|
|
|
if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) {
|
2006-02-21 18:07:35 +00:00
|
|
|
image += 8;
|
|
|
|
} else {
|
2007-04-27 21:35:02 +00:00
|
|
|
switch (roadside) {
|
2007-01-14 19:57:49 +00:00
|
|
|
case ROADSIDE_BARREN: pal = PALETTE_TO_BARE_LAND; break;
|
2006-06-19 20:13:50 +00:00
|
|
|
case ROADSIDE_GRASS: break;
|
|
|
|
default: image += 4; break; // Paved
|
|
|
|
}
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(image, pal);
|
2008-02-14 15:59:16 +00:00
|
|
|
if (HasTileRoadType(ti->tile, ROADTYPE_TRAM)) {
|
2007-05-26 07:58:49 +00:00
|
|
|
DrawGroundSprite(SPR_TRAMWAY_OVERLAY + (GetCrossingRoadAxis(ti->tile) ^ 1), pal);
|
|
|
|
DrawTramCatenary(ti, GetCrossingRoadBits(ti->tile));
|
|
|
|
}
|
2008-03-25 12:10:13 +00:00
|
|
|
if (HasCatenary(GetRailType(ti->tile))) DrawCatenary(ti);
|
2006-02-21 18:07:35 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-02-28 13:18:14 +00:00
|
|
|
default:
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_DEPOT: {
|
2007-07-26 16:51:10 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-04 18:41:16 +00:00
|
|
|
SpriteID palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-04 18:41:16 +00:00
|
|
|
const DrawTileSprites *dts;
|
2008-02-14 15:59:16 +00:00
|
|
|
if (HasTileRoadType(ti->tile, ROADTYPE_TRAM)) {
|
2007-05-25 22:07:40 +00:00
|
|
|
dts = &_tram_depot[GetRoadDepotDirection(ti->tile)];
|
|
|
|
} else {
|
|
|
|
dts = &_road_depot[GetRoadDepotDirection(ti->tile)];
|
|
|
|
}
|
|
|
|
|
2008-02-15 18:40:42 +00:00
|
|
|
DrawGroundSprite(dts->ground.sprite, PAL_NONE);
|
2005-02-22 15:39:45 +00:00
|
|
|
|
2008-04-03 19:55:40 +00:00
|
|
|
/* End now if buildings are invisible */
|
|
|
|
if (IsInvisibilitySet(TO_BUILDINGS)) break;
|
|
|
|
|
2008-04-04 18:41:16 +00:00
|
|
|
for (const DrawTileSeqStruct *dtss = dts->seq; dtss->image.sprite != 0; dtss++) {
|
2008-02-15 18:34:26 +00:00
|
|
|
SpriteID image = dtss->image.sprite;
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID pal;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!IsTransparencySet(TO_BUILDINGS) && HasBit(image, PALETTE_MODIFIER_COLOR)) {
|
2007-01-14 19:57:49 +00:00
|
|
|
pal = palette;
|
|
|
|
} else {
|
|
|
|
pal = PAL_NONE;
|
2006-08-05 16:57:39 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
AddSortableSpriteToDraw(
|
2007-01-14 19:57:49 +00:00
|
|
|
image, pal,
|
2006-08-06 18:36:36 +00:00
|
|
|
ti->x + dtss->delta_x, ti->y + dtss->delta_y,
|
|
|
|
dtss->size_x, dtss->size_y,
|
2007-07-26 14:07:11 +00:00
|
|
|
dtss->size_z, ti->z,
|
2007-11-10 01:17:15 +00:00
|
|
|
IsTransparencySet(TO_BUILDINGS)
|
2006-02-21 18:07:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
DrawBridgeMiddle(ti);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-05-21 21:58:31 +00:00
|
|
|
void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID palette = PLAYER_SPRITE_COLOR(_local_player);
|
2008-04-04 18:41:16 +00:00
|
|
|
const DrawTileSprites *dts = (rt == ROADTYPE_TRAM) ? &_tram_depot[dir] : &_road_depot[dir];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
x += 33;
|
|
|
|
y += 17;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-02-15 18:40:42 +00:00
|
|
|
DrawSprite(dts->ground.sprite, PAL_NONE, x, y);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-04 18:41:16 +00:00
|
|
|
for (const DrawTileSeqStruct *dtss = dts->seq; dtss->image.sprite != 0; dtss++) {
|
2006-08-06 18:36:36 +00:00
|
|
|
Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
|
2008-02-15 18:34:26 +00:00
|
|
|
SpriteID image = dtss->image.sprite;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-11-19 21:02:30 +00:00
|
|
|
DrawSprite(image, HasBit(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE, 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_Road(TileIndex tile, uint x, uint y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-08-06 16:32:49 +00:00
|
|
|
uint z;
|
|
|
|
Slope tileh = GetTileSlope(tile, &z);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
if (tileh == SLOPE_FLAT) return z;
|
2008-02-14 15:59:16 +00:00
|
|
|
if (IsNormalRoad(tile)) {
|
2007-07-26 16:51:10 +00:00
|
|
|
Foundation f = GetRoadFoundation(tileh, GetAllRoadBits(tile));
|
|
|
|
z += ApplyFoundationToSlope(f, &tileh);
|
2006-08-06 16:32:49 +00:00
|
|
|
return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
|
2006-03-21 22:06:32 +00:00
|
|
|
} else {
|
2006-04-23 19:35:36 +00:00
|
|
|
return z + TILE_HEIGHT;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-08-13 18:27:33 +00:00
|
|
|
}
|
|
|
|
|
2007-07-26 16:51:10 +00:00
|
|
|
static Foundation GetFoundation_Road(TileIndex tile, Slope tileh)
|
2004-08-13 18:27:33 +00:00
|
|
|
{
|
2008-02-14 15:59:16 +00:00
|
|
|
if (IsNormalRoad(tile)) {
|
2007-07-26 16:51:10 +00:00
|
|
|
return GetRoadFoundation(tileh, GetAllRoadBits(tile));
|
2006-03-21 22:06:32 +00:00
|
|
|
} else {
|
2007-07-26 16:51:10 +00:00
|
|
|
return FlatteningFoundation(tileh);
|
2004-08-13 18:27:33 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void GetAcceptedCargo_Road(TileIndex tile, AcceptedCargo ac)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* not used */
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void AnimateTile_Road(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
if (IsLevelCrossing(tile)) MarkTileDirtyByTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-06-19 20:13:50 +00:00
|
|
|
|
|
|
|
static const Roadside _town_road_types[][2] = {
|
|
|
|
{ ROADSIDE_GRASS, ROADSIDE_GRASS },
|
|
|
|
{ ROADSIDE_PAVED, ROADSIDE_PAVED },
|
|
|
|
{ ROADSIDE_PAVED, ROADSIDE_PAVED },
|
|
|
|
{ ROADSIDE_TREES, ROADSIDE_TREES },
|
|
|
|
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2006-06-19 20:13:50 +00:00
|
|
|
static const Roadside _town_road_types_2[][2] = {
|
|
|
|
{ ROADSIDE_GRASS, ROADSIDE_GRASS },
|
|
|
|
{ ROADSIDE_PAVED, ROADSIDE_PAVED },
|
|
|
|
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED },
|
|
|
|
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED },
|
|
|
|
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void TileLoop_Road(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-02-13 21:15:00 +00:00
|
|
|
switch (_opt.landscape) {
|
2007-03-22 03:42:43 +00:00
|
|
|
case LT_ARCTIC:
|
2007-03-20 13:47:00 +00:00
|
|
|
if (IsOnSnow(tile) != (GetTileZ(tile) > GetSnowLine())) {
|
2006-04-03 13:35:19 +00:00
|
|
|
ToggleSnow(tile);
|
2006-02-13 21:15:00 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-03-22 03:42:43 +00:00
|
|
|
case LT_TROPIC:
|
2006-04-03 13:35:19 +00:00
|
|
|
if (GetTropicZone(tile) == TROPICZONE_DESERT && !IsOnDesert(tile)) {
|
|
|
|
ToggleDesert(tile);
|
2006-02-13 21:15:00 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-02-14 15:59:16 +00:00
|
|
|
if (IsRoadDepot(tile)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-04 18:41:16 +00:00
|
|
|
const Town *t = ClosestTownFromTile(tile, (uint)-1);
|
2006-04-03 13:35:19 +00:00
|
|
|
if (!HasRoadWorks(tile)) {
|
2008-01-16 02:53:55 +00:00
|
|
|
HouseZonesBits grp = HZB_TOWN_EDGE;
|
2005-02-04 13:56:51 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (t != NULL) {
|
|
|
|
grp = GetTownRadiusGroup(t, tile);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Show an animation to indicate road work */
|
2004-09-11 09:55:19 +00:00
|
|
|
if (t->road_build_months != 0 &&
|
2008-01-16 02:53:55 +00:00
|
|
|
(DistanceManhattan(t->xy, tile) < 8 || grp != HZB_TOWN_EDGE) &&
|
2008-02-14 15:59:16 +00:00
|
|
|
IsNormalRoad(tile) && CountBits(GetAllRoadBits(tile)) > 1 ) {
|
2007-11-25 15:35:25 +00:00
|
|
|
if (GetTileSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicleOnGround(tile) && Chance16(1, 40)) {
|
2006-04-03 13:35:19 +00:00
|
|
|
StartRoadWorks(tile);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_21_JACKHAMMER, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
CreateEffectVehicleAbove(
|
2006-04-03 05:32:11 +00:00
|
|
|
TileX(tile) * TILE_SIZE + 7,
|
|
|
|
TileY(tile) * TILE_SIZE + 7,
|
2004-08-09 17:04:08 +00:00
|
|
|
0,
|
2005-02-12 15:53:32 +00:00
|
|
|
EV_BULLDOZER);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2006-04-03 13:35:19 +00:00
|
|
|
/* Adjust road ground type depending on 'grp' (grp is the distance to the center) */
|
2007-03-22 03:42:43 +00:00
|
|
|
const Roadside* new_rs = (_opt.landscape == LT_TOYLAND) ? _town_road_types_2[grp] : _town_road_types[grp];
|
2006-06-19 20:13:50 +00:00
|
|
|
Roadside cur_rs = GetRoadside(tile);
|
2006-04-03 13:35:19 +00:00
|
|
|
|
|
|
|
/* We have our desired type, do nothing */
|
2006-06-19 20:13:50 +00:00
|
|
|
if (cur_rs == new_rs[0]) return;
|
2006-04-03 13:35:19 +00:00
|
|
|
|
|
|
|
/* We have the pre-type of the desired type, switch to the desired type */
|
2006-06-19 20:13:50 +00:00
|
|
|
if (cur_rs == new_rs[1]) {
|
|
|
|
cur_rs = new_rs[0];
|
2006-04-03 13:35:19 +00:00
|
|
|
/* We have barren land, install the pre-type */
|
2006-06-19 20:13:50 +00:00
|
|
|
} else if (cur_rs == ROADSIDE_BARREN) {
|
|
|
|
cur_rs = new_rs[1];
|
2006-04-03 13:35:19 +00:00
|
|
|
/* We're totally off limits, remove any installation and make barren land */
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2006-06-19 20:13:50 +00:00
|
|
|
cur_rs = ROADSIDE_BARREN;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-06-19 20:13:50 +00:00
|
|
|
SetRoadside(tile, cur_rs);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
2006-04-03 13:35:19 +00:00
|
|
|
} else if (IncreaseRoadWorksCounter(tile)) {
|
|
|
|
TerminateRoadWorks(tile);
|
2007-09-26 16:12:43 +00:00
|
|
|
|
|
|
|
if (_patches.mod_road_rebuild) {
|
|
|
|
/* Generate a nicer town surface */
|
|
|
|
const RoadBits old_rb = GetAnyRoadBits(tile, ROADTYPE_ROAD);
|
|
|
|
const RoadBits new_rb = CleanUpRoadBits(tile, old_rb);
|
|
|
|
|
|
|
|
if (old_rb != new_rb) {
|
2008-01-28 12:40:31 +00:00
|
|
|
RemoveRoad(tile, DC_EXEC | DC_AUTO | DC_NO_WATER, (old_rb ^ new_rb), ROADTYPE_ROAD, true);
|
2007-09-26 16:12:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void ClickTile_Road(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-02-14 15:59:16 +00:00
|
|
|
if (IsRoadDepot(tile)) ShowDepotWindow(tile, VEH_ROAD);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 17:49:50 +00:00
|
|
|
/* Converts RoadBits to TrackBits */
|
2004-08-09 17:04:08 +00:00
|
|
|
static const byte _road_trackbits[16] = {
|
|
|
|
0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F,
|
|
|
|
};
|
|
|
|
|
2008-02-20 17:49:50 +00:00
|
|
|
static TrackStatus GetTileTrackStatus_Road(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
|
2005-06-24 12:38:35 +00:00
|
|
|
{
|
2008-02-20 17:49:50 +00:00
|
|
|
TrackdirBits trackdirbits = TRACKDIR_BIT_NONE;
|
|
|
|
TrackdirBits red_signals = TRACKDIR_BIT_NONE; // crossing barred
|
2006-02-23 07:26:49 +00:00
|
|
|
switch (mode) {
|
|
|
|
case TRANSPORT_RAIL:
|
2008-02-20 17:49:50 +00:00
|
|
|
if (IsLevelCrossing(tile)) trackdirbits = TrackBitsToTrackdirBits(GetCrossingRailBits(tile));
|
|
|
|
break;
|
2006-02-23 07:26:49 +00:00
|
|
|
|
|
|
|
case TRANSPORT_ROAD:
|
2008-02-20 17:49:50 +00:00
|
|
|
if ((GetRoadTypes(tile) & sub_mode) == 0) break;
|
2006-05-09 08:25:31 +00:00
|
|
|
switch (GetRoadTileType(tile)) {
|
2007-05-24 22:41:50 +00:00
|
|
|
case ROAD_TILE_NORMAL: {
|
2007-05-31 15:15:00 +00:00
|
|
|
const uint drd_to_multiplier[DRD_END] = { 0x101, 0x100, 0x1, 0x0 };
|
2008-02-18 16:11:31 +00:00
|
|
|
RoadType rt = (RoadType)FindFirstBit(sub_mode);
|
|
|
|
RoadBits bits = GetRoadBits(tile, rt);
|
|
|
|
|
|
|
|
/* no roadbit at this side of tile, return 0 */
|
2008-02-20 17:49:50 +00:00
|
|
|
if (side != INVALID_DIAGDIR && (DiagDirToRoadBits(side) & bits) == 0) break;
|
2008-02-18 16:11:31 +00:00
|
|
|
|
2007-05-31 15:15:00 +00:00
|
|
|
uint multiplier = drd_to_multiplier[rt == ROADTYPE_TRAM ? DRD_NONE : GetDisallowedRoadDirections(tile)];
|
2008-02-20 17:49:50 +00:00
|
|
|
if (!HasRoadWorks(tile)) trackdirbits = (TrackdirBits)(_road_trackbits[bits] * multiplier);
|
|
|
|
break;
|
2007-05-24 22:41:50 +00:00
|
|
|
}
|
2006-02-23 07:26:49 +00:00
|
|
|
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_CROSSING: {
|
2008-02-18 16:11:31 +00:00
|
|
|
Axis axis = GetCrossingRoadAxis(tile);
|
|
|
|
|
2008-02-20 17:49:50 +00:00
|
|
|
if (side != INVALID_DIAGDIR && axis != DiagDirToAxis(side)) break;
|
2006-03-19 17:15:33 +00:00
|
|
|
|
2008-02-20 17:49:50 +00:00
|
|
|
trackdirbits = TrackBitsToTrackdirBits(AxisToTrackBits(axis));
|
|
|
|
if (IsCrossingBarred(tile)) red_signals = trackdirbits;
|
|
|
|
break;
|
2006-02-23 07:26:49 +00:00
|
|
|
}
|
|
|
|
|
2006-02-23 08:20:28 +00:00
|
|
|
default:
|
2008-02-18 16:11:31 +00:00
|
|
|
case ROAD_TILE_DEPOT: {
|
|
|
|
DiagDirection dir = GetRoadDepotDirection(tile);
|
|
|
|
|
2008-02-20 17:49:50 +00:00
|
|
|
if (side != INVALID_DIAGDIR && side != dir) break;
|
2008-02-18 16:11:31 +00:00
|
|
|
|
2008-02-20 17:49:50 +00:00
|
|
|
trackdirbits = TrackBitsToTrackdirBits(AxisToTrackBits(DiagDirToAxis(dir)));
|
|
|
|
break;
|
2008-02-18 16:11:31 +00:00
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
}
|
2006-02-23 07:26:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-02-20 17:49:50 +00:00
|
|
|
return CombineTrackStatus(trackdirbits, red_signals);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const StringID _road_tile_strings[] = {
|
|
|
|
STR_1814_ROAD,
|
|
|
|
STR_1814_ROAD,
|
|
|
|
STR_1814_ROAD,
|
|
|
|
STR_1815_ROAD_WITH_STREETLIGHTS,
|
|
|
|
STR_1814_ROAD,
|
|
|
|
STR_1816_TREE_LINED_ROAD,
|
|
|
|
STR_1814_ROAD,
|
|
|
|
STR_1814_ROAD,
|
|
|
|
};
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void GetTileDesc_Road(TileIndex tile, TileDesc *td)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-06-04 11:56:32 +00:00
|
|
|
td->owner = GetTileOwner(tile);
|
2006-05-09 08:25:31 +00:00
|
|
|
switch (GetRoadTileType(tile)) {
|
|
|
|
case ROAD_TILE_CROSSING: td->str = STR_1818_ROAD_RAIL_LEVEL_CROSSING; break;
|
|
|
|
case ROAD_TILE_DEPOT: td->str = STR_1817_ROAD_VEHICLE_DEPOT; break;
|
2006-06-19 20:13:50 +00:00
|
|
|
default: td->str = _road_tile_strings[GetRoadside(tile)]; break;
|
2006-02-23 08:20:28 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-05-27 09:17:30 +00:00
|
|
|
/**
|
|
|
|
* Given the direction the road depot is pointing, this is the direction the
|
|
|
|
* vehicle should be travelling in in order to enter the depot.
|
|
|
|
*/
|
|
|
|
static const byte _roadveh_enter_depot_dir[4] = {
|
|
|
|
TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_X_NE, TRACKDIR_Y_SE
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2007-12-21 22:50:51 +00:00
|
|
|
static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-05-09 08:25:31 +00:00
|
|
|
switch (GetRoadTileType(tile)) {
|
|
|
|
case ROAD_TILE_CROSSING:
|
2008-01-17 19:49:06 +00:00
|
|
|
if (v->type == VEH_TRAIN) {
|
|
|
|
/* it should be barred */
|
|
|
|
assert(IsCrossingBarred(tile));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-02-21 18:07:35 +00:00
|
|
|
break;
|
|
|
|
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_DEPOT:
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_ROAD &&
|
2006-06-27 21:25:53 +00:00
|
|
|
v->u.road.frame == 11 &&
|
2007-05-27 09:17:30 +00:00
|
|
|
_roadveh_enter_depot_dir[GetRoadDepotDirection(tile)] == v->u.road.state) {
|
2007-06-11 14:00:16 +00:00
|
|
|
v->u.road.state = RVSB_IN_DEPOT;
|
|
|
|
v->vehstatus |= VS_HIDDEN;
|
|
|
|
v->direction = ReverseDir(v->direction);
|
2007-08-30 13:03:56 +00:00
|
|
|
if (v->Next() == NULL) VehicleEnterDepot(v);
|
2007-06-11 14:00:16 +00:00
|
|
|
v->tile = tile;
|
|
|
|
|
|
|
|
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static void ChangeTileOwner_Road(TileIndex tile, PlayerID old_player, PlayerID new_player)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-02-14 15:59:16 +00:00
|
|
|
if (IsRoadDepot(tile)) {
|
2007-05-26 23:18:42 +00:00
|
|
|
if (GetTileOwner(tile) == old_player) {
|
|
|
|
if (new_player == PLAYER_SPECTATOR) {
|
2008-02-09 15:07:31 +00:00
|
|
|
DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
|
2007-05-26 23:18:42 +00:00
|
|
|
} else {
|
|
|
|
SetTileOwner(tile, new_player);
|
|
|
|
}
|
2007-05-25 15:37:12 +00:00
|
|
|
}
|
2007-05-20 19:14:08 +00:00
|
|
|
return;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
|
2008-02-09 17:30:13 +00:00
|
|
|
/* ROADTYPE_ROAD denotes the tile owner, so update it too */
|
2008-02-14 15:59:16 +00:00
|
|
|
if (rt != ROADTYPE_ROAD && !HasTileRoadType(tile, rt)) continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
if (GetRoadOwner(tile, rt) == old_player) {
|
|
|
|
SetRoadOwner(tile, rt, new_player == PLAYER_SPECTATOR ? OWNER_NONE : new_player);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-20 19:14:08 +00:00
|
|
|
|
|
|
|
if (IsLevelCrossing(tile)) {
|
2007-05-25 15:37:12 +00:00
|
|
|
if (GetTileOwner(tile) == old_player) {
|
|
|
|
if (new_player == PLAYER_SPECTATOR) {
|
2008-02-18 18:35:36 +00:00
|
|
|
DoCommand(tile, 0, GetCrossingRailTrack(tile), DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL);
|
2007-05-25 15:37:12 +00:00
|
|
|
} else {
|
|
|
|
SetTileOwner(tile, new_player);
|
|
|
|
}
|
|
|
|
}
|
2007-05-20 19:14:08 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-08-30 17:17:04 +00:00
|
|
|
static CommandCost TerraformTile_Road(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
|
|
|
|
{
|
2007-09-14 22:27:40 +00:00
|
|
|
if (_patches.build_on_slopes && AutoslopeEnabled()) {
|
|
|
|
switch (GetRoadTileType(tile)) {
|
|
|
|
case ROAD_TILE_CROSSING:
|
2008-01-09 16:55:48 +00:00
|
|
|
if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) && HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
|
2007-09-14 22:27:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ROAD_TILE_DEPOT:
|
2008-01-09 16:55:48 +00:00
|
|
|
if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRoadDepotDirection(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
|
2007-09-14 22:27:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ROAD_TILE_NORMAL: {
|
|
|
|
RoadBits bits = GetAllRoadBits(tile);
|
|
|
|
RoadBits bits_copy = bits;
|
|
|
|
/* Check if the slope-road_bits combination is valid at all, i.e. it is save to call GetRoadFoundation(). */
|
2008-03-27 14:26:31 +00:00
|
|
|
if (!CmdFailed(CheckRoadSlope(tileh_new, &bits_copy, ROAD_NONE, ROAD_NONE))) {
|
2007-09-14 22:27:40 +00:00
|
|
|
/* CheckRoadSlope() sometimes changes the road_bits, if it does not agree with them. */
|
|
|
|
if (bits == bits_copy) {
|
|
|
|
uint z_old;
|
|
|
|
Slope tileh_old = GetTileSlope(tile, &z_old);
|
|
|
|
|
|
|
|
/* Get the slope on top of the foundation */
|
|
|
|
z_old += ApplyFoundationToSlope(GetRoadFoundation(tileh_old, bits), &tileh_old);
|
|
|
|
z_new += ApplyFoundationToSlope(GetRoadFoundation(tileh_new, bits), &tileh_new);
|
|
|
|
|
|
|
|
/* The surface slope must not be changed */
|
2008-01-09 16:55:48 +00:00
|
|
|
if ((z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
|
2007-09-14 22:27:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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_road_procs = {
|
2006-08-22 14:38:37 +00:00
|
|
|
DrawTile_Road, /* draw_tile_proc */
|
|
|
|
GetSlopeZ_Road, /* get_slope_z_proc */
|
|
|
|
ClearTile_Road, /* clear_tile_proc */
|
|
|
|
GetAcceptedCargo_Road, /* get_accepted_cargo_proc */
|
|
|
|
GetTileDesc_Road, /* get_tile_desc_proc */
|
|
|
|
GetTileTrackStatus_Road, /* get_tile_track_status_proc */
|
|
|
|
ClickTile_Road, /* click_tile_proc */
|
|
|
|
AnimateTile_Road, /* animate_tile_proc */
|
|
|
|
TileLoop_Road, /* tile_loop_clear */
|
|
|
|
ChangeTileOwner_Road, /* change_tile_owner_clear */
|
|
|
|
NULL, /* get_produced_cargo_proc */
|
|
|
|
VehicleEnter_Road, /* vehicle_enter_tile_proc */
|
2007-07-26 16:51:10 +00:00
|
|
|
GetFoundation_Road, /* get_foundation_proc */
|
2007-08-30 17:17:04 +00:00
|
|
|
TerraformTile_Road, /* terraform_tile_proc */
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|