2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file road_cmd.cpp Commands related to road tiles. */
|
2007-03-28 20:41:35 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2007-02-24 09:42:39 +00:00
|
|
|
#include "cmd_helper.h"
|
2007-12-18 20:38:16 +00:00
|
|
|
#include "road_internal.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"
|
2006-05-27 16:12:16 +00:00
|
|
|
#include "yapf/yapf.h"
|
2008-04-17 19:10:30 +00:00
|
|
|
#include "depot_base.h"
|
2007-04-27 21:35:02 +00:00
|
|
|
#include "newgrf.h"
|
2007-05-24 09:31:09 +00:00
|
|
|
#include "station_map.h"
|
2008-01-07 00:57:19 +00:00
|
|
|
#include "variables.h"
|
2007-09-14 22:27:40 +00:00
|
|
|
#include "autoslope.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"
|
2007-12-29 09:24:26 +00:00
|
|
|
#include "sound_func.h"
|
2008-01-23 22:34:04 +00:00
|
|
|
#include "tunnelbridge.h"
|
2009-01-31 20:16:06 +00:00
|
|
|
#include "cheat_type.h"
|
2008-04-20 08:43:31 +00:00
|
|
|
#include "functions.h"
|
2008-04-20 11:12:07 +00:00
|
|
|
#include "effectvehicle_func.h"
|
2008-05-08 16:48:29 +00:00
|
|
|
#include "elrail_func.h"
|
2009-02-06 15:39:34 +00:00
|
|
|
#include "roadveh.h"
|
2009-06-26 13:44:14 +00:00
|
|
|
#include "town.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
|
|
|
|
2008-10-19 15:39:12 +00:00
|
|
|
/**
|
|
|
|
* Verify whether a road vehicle is available.
|
|
|
|
* @return \c true if at least one road vehicle is available, \c false if not
|
|
|
|
*/
|
2008-05-18 17:40:13 +00:00
|
|
|
bool RoadVehiclesAreBuilt()
|
|
|
|
{
|
2009-05-26 22:45:48 +00:00
|
|
|
const RoadVehicle *rv;
|
|
|
|
FOR_ALL_ROADVEHICLES(rv) return true;
|
2008-05-18 17:40:13 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2008-05-24 22:15:10 +00:00
|
|
|
/**
|
|
|
|
* Is it allowed to remove the given road bits from the given tile?
|
|
|
|
* @param tile the tile to remove the road from
|
|
|
|
* @param remove the roadbits that are going to be removed
|
|
|
|
* @param owner the actual owner of the roadbits of the tile
|
|
|
|
* @param rt the road type to remove the bits from
|
|
|
|
* @param flags command flags
|
|
|
|
* @param town_check Shall the town rating checked/affected
|
|
|
|
* @return true when it is allowed to remove the road bits
|
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType rt, DoCommandFlag flags, bool town_check)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
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. */
|
2008-09-30 20:39:50 +00:00
|
|
|
if (_current_company == OWNER_WATER ||
|
2009-05-17 01:00:56 +00:00
|
|
|
(rt == ROADTYPE_ROAD && !Company::IsValidID(_current_company))) 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
|
|
|
|
2008-05-24 22:15:10 +00:00
|
|
|
if (!town_check) return true;
|
|
|
|
|
2006-02-13 21:15:00 +00:00
|
|
|
if (_cheats.magic_bulldozer.value) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-24 22:15:10 +00:00
|
|
|
Town *t = ClosestTownFromTile(tile, UINT_MAX);
|
|
|
|
if (t == NULL) return true;
|
|
|
|
|
|
|
|
/* check if you're allowed to remove the street owned by a town
|
|
|
|
* removal allowance depends on difficulty setting */
|
|
|
|
if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return false;
|
|
|
|
|
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);
|
2009-06-01 11:43:36 +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
|
|
|
|
2008-05-24 22:15:10 +00:00
|
|
|
int rating_decrease = RATING_ROAD_DOWN_STEP_EDGE;
|
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) {
|
2007-03-28 20:41:35 +00:00
|
|
|
/* you can remove all kind of roads with extra dynamite */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (!_settings_game.construction.extra_dynamite) {
|
2008-05-24 22:15:10 +00:00
|
|
|
SetDParam(0, t->index);
|
2009-04-21 23:40:56 +00:00
|
|
|
_error_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS;
|
2008-05-24 22:15:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
rating_decrease = RATING_ROAD_DOWN_STEP_INNER;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2009-02-11 18:50:47 +00:00
|
|
|
ChangeTownRating(t, rating_decrease, RATING_ROAD_MINIMUM, flags);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits pieces, RoadType rt, bool crossing_check, bool town_check = true)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-05-24 19:36:20 +00:00
|
|
|
RoadTypes rts = GetRoadTypes(tile);
|
|
|
|
/* The tile doesn't have the given road type */
|
|
|
|
if (!HasBit(rts, rt)) return CMD_ERROR;
|
|
|
|
|
2007-05-24 09:31:09 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2007-07-29 23:42:59 +00:00
|
|
|
case MP_ROAD:
|
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;
|
2008-09-07 11:23:10 +00:00
|
|
|
if (HasVehicleOnTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile))) return CMD_ERROR;
|
2008-01-23 14:51:36 +00:00
|
|
|
break;
|
2007-05-24 09:31:09 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2005-04-03 13:37:35 +00:00
|
|
|
|
2009-03-02 22:57:47 +00:00
|
|
|
if (!CheckAllowRemoveRoad(tile, pieces, GetRoadOwner(tile, rt), rt, flags, town_check)) 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));
|
|
|
|
|
2009-03-02 22:57:47 +00:00
|
|
|
/* If the owner of the bridge sells all it's road, also move the ownership
|
|
|
|
* to the owner of the other roadtype. */
|
|
|
|
RoadType other_rt = (rt == ROADTYPE_ROAD) ? ROADTYPE_TRAM : ROADTYPE_ROAD;
|
|
|
|
Owner other_owner = GetRoadOwner(tile, other_rt);
|
|
|
|
if (other_owner != GetTileOwner(tile)) {
|
|
|
|
SetTileOwner(tile, other_owner);
|
|
|
|
SetTileOwner(other_end, other_owner);
|
|
|
|
}
|
|
|
|
|
2007-05-24 09:31:09 +00:00
|
|
|
/* 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 {
|
2008-09-13 17:06:44 +00:00
|
|
|
assert(IsDriveThroughStopTile(tile));
|
|
|
|
cost.AddCost(_price.remove_road * 2);
|
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
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
if (HasRoadWorks(tile) && _current_company != OWNER_WATER) 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) ||
|
2008-05-29 15:13:28 +00:00
|
|
|
(tileh != SLOPE_FLAT && !_settings_game.construction.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;
|
|
|
|
}
|
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2008-04-29 16:36:44 +00:00
|
|
|
if (HasRoadWorks(tile)) {
|
|
|
|
/* flooding tile with road works, don't forget to remove the effect vehicle too */
|
2008-09-30 20:39:50 +00:00
|
|
|
assert(_current_company == OWNER_WATER);
|
2009-05-26 22:45:48 +00:00
|
|
|
EffectVehicle *v;
|
|
|
|
FOR_ALL_EFFECTVEHICLES(v) {
|
|
|
|
if (TileVirtXY(v->x_pos, v->y_pos) == tile) {
|
2008-04-29 16:36:44 +00:00
|
|
|
delete v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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 {
|
2008-10-25 13:51:47 +00:00
|
|
|
if (rt == ROADTYPE_ROAD && IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN)) {
|
2008-11-18 22:43:59 +00:00
|
|
|
/* Update nearest-town index */
|
2009-03-08 01:20:11 +00:00
|
|
|
const Town *town = CalcClosestTownFromTile(tile);
|
2008-11-18 22:43:59 +00:00
|
|
|
SetTownIndex(tile, town == NULL ? (TownID)INVALID_TOWN : town->index);
|
2008-10-25 13:51:47 +00:00
|
|
|
}
|
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;
|
2008-11-18 22:43:59 +00:00
|
|
|
* we can't draw the crossing without roadbits ;) */
|
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 (flags & DC_EXEC) {
|
2009-05-15 16:07:36 +00:00
|
|
|
Track railtrack = GetCrossingRailTrack(tile);
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
|
|
|
|
if (rts == ROADTYPES_NONE) {
|
2008-08-02 22:48:27 +00:00
|
|
|
TrackBits tracks = GetCrossingRailBits(tile);
|
2009-07-21 22:37:10 +00:00
|
|
|
bool reserved = HasCrossingReservation(tile);
|
2008-08-02 22:48:27 +00:00
|
|
|
MakeRailNormal(tile, GetTileOwner(tile), tracks, GetRailType(tile));
|
|
|
|
if (reserved) SetTrackReservation(tile, tracks);
|
2007-05-20 19:14:08 +00:00
|
|
|
} else {
|
|
|
|
SetRoadTypes(tile, rts);
|
2008-10-25 13:51:47 +00:00
|
|
|
/* If we ever get HWAY and it is possible without road then we will need to promote ownership and invalidate town index here, too */
|
2007-05-20 19:14:08 +00:00
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2009-05-15 16:07:36 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, railtrack);
|
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
|
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost CmdRemoveRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2008-01-28 12:40:31 +00:00
|
|
|
{
|
|
|
|
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-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.construction.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-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.construction.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
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
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
|
2008-09-30 20:39:50 +00:00
|
|
|
* if a non-company is building the road */
|
2009-05-17 01:00:56 +00:00
|
|
|
if ((Company::IsValidID(_current_company) && p2 != 0) || (_current_company == OWNER_TOWN && !Town::IsValidID(p2))) return CMD_ERROR;
|
2008-10-25 13:51:47 +00:00
|
|
|
if (_current_company != OWNER_TOWN) {
|
2009-03-08 01:20:11 +00:00
|
|
|
const Town *town = CalcClosestTownFromTile(tile);
|
2008-10-25 13:51:47 +00:00
|
|
|
p2 = (town != NULL) ? town->index : (TownID)INVALID_TOWN;
|
|
|
|
}
|
2007-02-24 09:42:39 +00:00
|
|
|
|
|
|
|
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 */
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
|
2007-05-31 15:15:00 +00:00
|
|
|
}
|
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 */
|
2008-09-30 20:39:50 +00:00
|
|
|
if (toggle_drd != DRD_NONE && rt != ROADTYPE_TRAM && IsRoadOwner(tile, ROADTYPE_ROAD, _current_company)) {
|
2009-04-21 23:40:56 +00:00
|
|
|
if (crossing) return_cmd_error(STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
|
2007-05-31 15:15:00 +00:00
|
|
|
|
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 */
|
2009-06-01 11:43:36 +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
|
|
|
}
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
2006-02-23 07:26:49 +00:00
|
|
|
}
|
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-03-27 14:26:31 +00:00
|
|
|
other_bits = GetCrossingRoadBits(tile);
|
|
|
|
if (pieces & ComplementRoadBits(other_bits)) goto do_clear;
|
2008-09-13 17:06:44 +00:00
|
|
|
pieces = other_bits; // we need to pay for both roadbits
|
2008-09-13 17:37:18 +00:00
|
|
|
|
2009-04-21 23:40:56 +00:00
|
|
|
if (HasTileRoadType(tile, rt)) return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
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)) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
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)) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
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) {
|
2009-05-15 16:07:36 +00:00
|
|
|
Track railtrack = AxisToTrack(OtherAxis(roaddir));
|
|
|
|
YapfNotifyTrackLayoutChange(tile, railtrack);
|
2007-05-26 07:58:49 +00:00
|
|
|
/* Always add road to the roadtypes (can't draw without it) */
|
2009-07-21 22:37:10 +00:00
|
|
|
bool reserved = HasBit(GetRailReservationTrackBits(tile), railtrack);
|
2009-03-02 22:57:47 +00:00
|
|
|
MakeRoadCrossing(tile, _current_company, _current_company, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2);
|
2008-08-02 22:48:27 +00:00
|
|
|
SetCrossingReservation(tile, reserved);
|
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
|
|
|
|
2008-09-13 17:26:44 +00:00
|
|
|
case MP_STATION: {
|
|
|
|
if (!IsDriveThroughStopTile(tile)) goto do_clear;
|
|
|
|
|
|
|
|
RoadBits curbits = AxisToRoadBits(DiagDirToAxis(GetRoadStopDir(tile)));
|
|
|
|
if (pieces & ~curbits) goto do_clear;
|
|
|
|
pieces = curbits; // we need to pay for both roadbits
|
2008-09-13 17:37:18 +00:00
|
|
|
|
2009-04-21 23:40:56 +00:00
|
|
|
if (HasTileRoadType(tile, rt)) return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
2008-09-13 17:26:44 +00:00
|
|
|
} break;
|
2007-05-24 09:31:09 +00:00
|
|
|
|
|
|
|
case MP_TUNNELBRIDGE:
|
2008-01-23 14:51:36 +00:00
|
|
|
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
|
2008-06-24 11:42:01 +00:00
|
|
|
if (MirrorRoadBits(DiagDirToRoadBits(GetTunnelBridgeDirection(tile))) != pieces) return CMD_ERROR;
|
2009-04-21 23:40:56 +00:00
|
|
|
if (HasTileRoadType(tile, rt)) return_cmd_error(STR_ERROR_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 */
|
2008-09-07 11:23:10 +00:00
|
|
|
if (HasVehicleOnTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile))) return CMD_ERROR;
|
2008-01-23 14:51:36 +00:00
|
|
|
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
|
2009-02-08 12:25:13 +00:00
|
|
|
* current setting is turned off */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (CmdFailed(ret) || (ret.GetCost() != 0 && !_settings_game.construction.build_on_slopes)) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
2007-05-26 22:19:04 +00:00
|
|
|
}
|
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) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
2008-01-23 00:36:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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));
|
2008-09-30 20:39:50 +00:00
|
|
|
SetRoadOwner(tile, rt, _current_company);
|
2008-10-25 13:51:47 +00:00
|
|
|
if (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));
|
2009-03-02 22:57:47 +00:00
|
|
|
SetRoadOwner(other_end, rt, _current_company);
|
|
|
|
SetRoadOwner(tile, rt, _current_company);
|
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:
|
2008-09-13 17:26:44 +00:00
|
|
|
assert(IsDriveThroughStopTile(tile));
|
2007-05-24 09:31:09 +00:00
|
|
|
SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
|
2009-03-02 22:57:47 +00:00
|
|
|
SetRoadOwner(tile, rt, _current_company);
|
2007-05-24 09:31:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-03-02 22:57:47 +00:00
|
|
|
MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, _current_company, _current_company);
|
2007-05-24 09:31:09 +00:00
|
|
|
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
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost CmdBuildLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
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-06-24 11:42:01 +00:00
|
|
|
_error_message = INVALID_STRING_ID;
|
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)) {
|
2009-04-21 23:40:56 +00:00
|
|
|
if (_error_message != STR_ERROR_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
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost CmdRemoveLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
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-04-13 10:32:29 +00:00
|
|
|
RemoveRoad(tile, flags, bits, rt, true, false);
|
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
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
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 && (
|
2008-05-29 15:13:28 +00:00
|
|
|
!_settings_game.construction.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
|
|
|
)) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_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
|
|
|
|
2009-04-21 23:40:56 +00:00
|
|
|
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2008-04-23 20:56:08 +00:00
|
|
|
if (!Depot::CanAllocateItem()) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-09-11 09:55:19 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2008-04-23 20:56:08 +00:00
|
|
|
Depot *dep = new Depot(tile);
|
2008-10-14 18:38:51 +00:00
|
|
|
dep->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-10-25 13:51:47 +00:00
|
|
|
MakeRoadDepot(tile, _current_company, dir, rt, dep->town_index);
|
2006-03-01 06:39:04 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
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
|
|
|
}
|
|
|
|
|
2009-02-09 21:20:05 +00:00
|
|
|
static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlag flags)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-09-30 20:39:50 +00:00
|
|
|
if (!CheckTileOwnership(tile) && _current_company != 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);
|
2009-06-24 19:26:41 +00:00
|
|
|
delete Depot::GetByTile(tile);
|
2007-08-02 22:33:53 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2009-02-09 21:20:05 +00:00
|
|
|
static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlag 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
|
|
|
|
2009-01-12 19:49:23 +00:00
|
|
|
/* Clear the road if only one piece is on the tile OR we are not using the DC_AUTO flag */
|
2009-01-12 17:11:45 +00:00
|
|
|
if ((CountBits(b) == 1 && GetRoadBits(tile, ROADTYPE_TRAM) == ROAD_NONE) || !(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
|
|
|
}
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_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
|
|
|
|
2009-04-21 23:40:56 +00:00
|
|
|
if (flags & DC_AUTO) return_cmd_error(STR_ERROR_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. */
|
2009-03-02 22:57:47 +00:00
|
|
|
RoadType rt = ROADTYPE_TRAM;
|
2008-04-07 22:15:31 +00:00
|
|
|
do {
|
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
|
|
|
}
|
2008-04-07 22:15:31 +00:00
|
|
|
} while (rt-- != ROADTYPE_ROAD);
|
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) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
|
|
|
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) &&
|
2008-05-29 15:13:28 +00:00
|
|
|
!(_settings_game.game_creation.landscape == LT_TROPIC && HasGrfMiscBit(GMB_DESERT_PAVED_ROADS) &&
|
2007-04-27 21:35:02 +00:00
|
|
|
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
|
|
|
|
2008-10-19 15:39:12 +00:00
|
|
|
/** Tile callback function for rendering a road tile to the screen */
|
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-08-02 22:47:34 +00:00
|
|
|
|
|
|
|
/* PBS debugging, draw reserved tracks darker */
|
2009-07-21 22:37:10 +00:00
|
|
|
if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && HasCrossingReservation(ti->tile)) {
|
2008-08-02 22:47:34 +00:00
|
|
|
DrawGroundSprite(GetCrossingRoadAxis(ti->tile) == AXIS_Y ? GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.single_y : GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.single_x, PALETTE_CRASH);
|
|
|
|
}
|
|
|
|
|
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-05-08 16:48:29 +00:00
|
|
|
if (HasCatenaryDrawn(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
|
|
|
|
2009-02-09 02:57:15 +00:00
|
|
|
SpriteID palette = COMPANY_SPRITE_COLOUR(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
|
|
|
|
2009-02-09 02:57:15 +00:00
|
|
|
if (!IsTransparencySet(TO_BUILDINGS) && HasBit(image, PALETTE_MODIFIER_COLOUR)) {
|
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
|
|
|
{
|
2009-02-09 02:57:15 +00:00
|
|
|
SpriteID palette = COMPANY_SPRITE_COLOUR(_local_company);
|
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
|
|
|
|
2009-02-09 02:57:15 +00:00
|
|
|
DrawSprite(image, HasBit(image, PALETTE_MODIFIER_COLOUR) ? palette : PAL_NONE, x + pt.x, y + pt.y);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-22 15:13:50 +00:00
|
|
|
/**
|
|
|
|
* Updates cached nearest town for all road tiles
|
2008-11-18 22:43:59 +00:00
|
|
|
* @param invalidate are we just invalidating cached data?
|
2009-05-22 15:13:50 +00:00
|
|
|
* @param ignore town that should be ignored (because we are deleting it now)
|
2008-11-18 22:43:59 +00:00
|
|
|
* @pre invalidate == true implies _generating_world == true
|
|
|
|
*/
|
2009-07-05 13:21:51 +00:00
|
|
|
void UpdateNearestTownForRoadTiles(bool invalidate)
|
2008-10-25 13:51:47 +00:00
|
|
|
{
|
2008-11-18 22:43:59 +00:00
|
|
|
assert(!invalidate || _generating_world);
|
|
|
|
|
|
|
|
for (TileIndex t = 0; t < MapSize(); t++) {
|
|
|
|
if (IsTileType(t, MP_ROAD) && !HasTownOwnedRoad(t)) {
|
|
|
|
TownID tid = (TownID)INVALID_TOWN;
|
|
|
|
if (!invalidate) {
|
2009-07-05 13:21:51 +00:00
|
|
|
const Town *town = CalcClosestTownFromTile(t);
|
2008-11-18 22:43:59 +00:00
|
|
|
if (town != NULL) tid = town->index;
|
|
|
|
}
|
|
|
|
SetTownIndex(t, tid);
|
2008-10-25 13:51:47 +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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2008-05-29 15:13:28 +00:00
|
|
|
switch (_settings_game.game_creation.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-10-14 18:38:51 +00:00
|
|
|
const Town *t = ClosestTownFromTile(tile, UINT_MAX);
|
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 ) {
|
2009-02-11 20:41:17 +00:00
|
|
|
if (GetFoundationSlope(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) */
|
2009-01-10 00:31:47 +00:00
|
|
|
const Roadside *new_rs = (_settings_game.game_creation.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
|
|
|
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.economy.mod_road_rebuild) {
|
2007-09-26 16:12:43 +00:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-02 22:42:05 +00:00
|
|
|
static bool ClickTile_Road(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-01-02 22:42:05 +00:00
|
|
|
if (!IsRoadDepot(tile)) return false;
|
|
|
|
|
|
|
|
ShowDepotWindow(tile, VEH_ROAD);
|
|
|
|
return true;
|
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-05-14 18:31:21 +00:00
|
|
|
trackdirbits = TrackBitsToTrackdirBits(DiagDirToDiagTrackBits(dir));
|
2008-02-20 17:49:50 +00:00
|
|
|
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[] = {
|
2009-04-21 23:40:56 +00:00
|
|
|
STR_ROAD_DESCRIPTION_ROAD,
|
|
|
|
STR_ROAD_DESCRIPTION_ROAD,
|
|
|
|
STR_ROAD_DESCRIPTION_ROAD,
|
|
|
|
STR_ROAD_DESCRIPTION_ROAD_WITH_STREETLIGHTS,
|
|
|
|
STR_ROAD_DESCRIPTION_ROAD,
|
|
|
|
STR_ROAD_DESCRIPTION_TREE_LINED_ROAD,
|
|
|
|
STR_ROAD_DESCRIPTION_ROAD,
|
|
|
|
STR_ROAD_DESCRIPTION_ROAD,
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void GetTileDesc_Road(TileIndex tile, TileDesc *td)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-05-21 22:15:39 +00:00
|
|
|
Owner rail_owner = INVALID_OWNER;
|
|
|
|
Owner road_owner = INVALID_OWNER;
|
|
|
|
Owner tram_owner = INVALID_OWNER;
|
|
|
|
|
2006-05-09 08:25:31 +00:00
|
|
|
switch (GetRoadTileType(tile)) {
|
2008-05-21 22:15:39 +00:00
|
|
|
case ROAD_TILE_CROSSING: {
|
2009-04-21 23:40:56 +00:00
|
|
|
td->str = STR_ROAD_DESCRIPTION_ROAD_RAIL_LEVEL_CROSSING;
|
2008-05-21 22:15:39 +00:00
|
|
|
RoadTypes rts = GetRoadTypes(tile);
|
|
|
|
rail_owner = GetTileOwner(tile);
|
|
|
|
if (HasBit(rts, ROADTYPE_ROAD)) road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
|
|
|
|
if (HasBit(rts, ROADTYPE_TRAM)) tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ROAD_TILE_DEPOT:
|
2009-04-21 23:40:56 +00:00
|
|
|
td->str = STR_ROAD_DESCRIPTION_ROAD_VEHICLE_DEPOT;
|
2008-05-21 22:15:39 +00:00
|
|
|
road_owner = GetTileOwner(tile); // Tile has only one owner, roadtype does not matter
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: {
|
|
|
|
RoadTypes rts = GetRoadTypes(tile);
|
2009-04-21 23:40:56 +00:00
|
|
|
td->str = (HasBit(rts, ROADTYPE_ROAD) ? _road_tile_strings[GetRoadside(tile)] : STR_ROAD_DESCRIPTION_TRAMWAY);
|
2008-05-21 22:15:39 +00:00
|
|
|
if (HasBit(rts, ROADTYPE_ROAD)) road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
|
|
|
|
if (HasBit(rts, ROADTYPE_TRAM)) tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now we have to discover, if the tile has only one owner or many:
|
|
|
|
* - Find a first_owner of the tile. (Currently road or tram must be present, but this will break when the third type becomes available)
|
|
|
|
* - Compare the found owner with the other owners, and test if they differ.
|
|
|
|
* Note: If road exists it will be the first_owner.
|
|
|
|
*/
|
|
|
|
Owner first_owner = (road_owner == INVALID_OWNER ? tram_owner : road_owner);
|
|
|
|
bool mixed_owners = (tram_owner != INVALID_OWNER && tram_owner != first_owner) || (rail_owner != INVALID_OWNER && rail_owner != first_owner);
|
|
|
|
|
|
|
|
if (mixed_owners) {
|
|
|
|
/* Multiple owners */
|
2009-04-21 23:40:56 +00:00
|
|
|
td->owner_type[0] = (rail_owner == INVALID_OWNER ? STR_NULL : STR_LAND_AREA_INFORMATION_RAIL_OWNER);
|
2008-05-21 22:15:39 +00:00
|
|
|
td->owner[0] = rail_owner;
|
2009-04-21 23:40:56 +00:00
|
|
|
td->owner_type[1] = (road_owner == INVALID_OWNER ? STR_NULL : STR_LAND_AREA_INFORMATION_ROAD_OWNER);
|
2008-05-21 22:15:39 +00:00
|
|
|
td->owner[1] = road_owner;
|
2009-04-21 23:40:56 +00:00
|
|
|
td->owner_type[2] = (tram_owner == INVALID_OWNER ? STR_NULL : STR_LAND_AREA_INFORMATION_TRAM_OWNER);
|
2008-05-21 22:15:39 +00:00
|
|
|
td->owner[2] = tram_owner;
|
|
|
|
} else {
|
|
|
|
/* One to rule them all */
|
|
|
|
td->owner[0] = first_owner;
|
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)) {
|
2009-05-22 20:22:20 +00:00
|
|
|
case ROAD_TILE_DEPOT: {
|
|
|
|
if (v->type != VEH_ROAD) break;
|
|
|
|
|
2009-06-06 16:54:22 +00:00
|
|
|
RoadVehicle *rv = RoadVehicle::From(v);
|
2009-05-22 20:22:20 +00:00
|
|
|
if (rv->frame == RVC_DEPOT_STOP_FRAME &&
|
|
|
|
_roadveh_enter_depot_dir[GetRoadDepotDirection(tile)] == rv->state) {
|
|
|
|
rv->state = RVSB_IN_DEPOT;
|
|
|
|
rv->vehstatus |= VS_HIDDEN;
|
|
|
|
rv->direction = ReverseDir(rv->direction);
|
|
|
|
if (rv->Next() == NULL) VehicleEnterDepot(rv);
|
|
|
|
rv->tile = tile;
|
|
|
|
|
|
|
|
InvalidateWindowData(WC_VEHICLE_DEPOT, rv->tile);
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
2009-05-22 20:22:20 +00:00
|
|
|
} break;
|
2006-02-21 18:07:35 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
static void ChangeTileOwner_Road(TileIndex tile, Owner old_owner, Owner new_owner)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-02-14 15:59:16 +00:00
|
|
|
if (IsRoadDepot(tile)) {
|
2008-09-30 20:39:50 +00:00
|
|
|
if (GetTileOwner(tile) == old_owner) {
|
|
|
|
if (new_owner == INVALID_OWNER) {
|
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 {
|
2008-09-30 20:39:50 +00:00
|
|
|
SetTileOwner(tile, new_owner);
|
2007-05-26 23:18:42 +00:00
|
|
|
}
|
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-05-24 19:36:20 +00:00
|
|
|
/* Update all roadtypes, no matter if they are present */
|
2008-09-30 20:39:50 +00:00
|
|
|
if (GetRoadOwner(tile, rt) == old_owner) {
|
|
|
|
SetRoadOwner(tile, rt, new_owner == INVALID_OWNER ? OWNER_NONE : new_owner);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-20 19:14:08 +00:00
|
|
|
|
|
|
|
if (IsLevelCrossing(tile)) {
|
2008-09-30 20:39:50 +00:00
|
|
|
if (GetTileOwner(tile) == old_owner) {
|
|
|
|
if (new_owner == INVALID_OWNER) {
|
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 {
|
2008-09-30 20:39:50 +00:00
|
|
|
SetTileOwner(tile, new_owner);
|
2007-05-25 15:37:12 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-20 19:14:08 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 21:20:05 +00:00
|
|
|
static CommandCost TerraformTile_Road(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
|
2007-08-30 17:17:04 +00:00
|
|
|
{
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.construction.build_on_slopes && AutoslopeEnabled()) {
|
2007-09-14 22:27:40 +00:00
|
|
|
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;
|
2008-08-25 20:54:34 +00:00
|
|
|
/* Check if the slope-road_bits combination is valid at all, i.e. it is safe 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);
|
|
|
|
}
|
|
|
|
|
2008-10-19 15:39:12 +00:00
|
|
|
/** Tile callback functions for road tiles */
|
2007-01-10 18:56:51 +00:00
|
|
|
extern const TileTypeProcs _tile_type_road_procs = {
|
2008-10-19 15:39:12 +00:00
|
|
|
DrawTile_Road, // draw_tile_proc
|
|
|
|
GetSlopeZ_Road, // get_slope_z_proc
|
|
|
|
ClearTile_Road, // clear_tile_proc
|
2009-06-25 20:08:59 +00:00
|
|
|
NULL, // add_accepted_cargo_proc
|
2008-10-19 15:39:12 +00:00
|
|
|
GetTileDesc_Road, // get_tile_desc_proc
|
|
|
|
GetTileTrackStatus_Road, // get_tile_track_status_proc
|
|
|
|
ClickTile_Road, // click_tile_proc
|
2009-06-26 20:03:16 +00:00
|
|
|
NULL, // animate_tile_proc
|
2008-10-19 15:39:12 +00:00
|
|
|
TileLoop_Road, // tile_loop_clear
|
|
|
|
ChangeTileOwner_Road, // change_tile_owner_clear
|
2009-06-27 17:05:20 +00:00
|
|
|
NULL, // add_produced_cargo_proc
|
2008-10-19 15:39:12 +00:00
|
|
|
VehicleEnter_Road, // vehicle_enter_tile_proc
|
|
|
|
GetFoundation_Road, // get_foundation_proc
|
|
|
|
TerraformTile_Road, // terraform_tile_proc
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|