|
@@ -651,97 +651,97 @@ int32 CmdRemoveRailroadTrack(int x, int
|
|
|
* @param p2 depot direction (0 through 3), where 0 is NE, 1 is SE, 2 is SW, 3 is NW
|
|
|
*
|
|
|
* @todo When checking for the tile slope,
|
|
|
* distingush between "Flat land required" and "land sloped in wrong direction"
|
|
|
*/
|
|
|
int32 CmdBuildTrainDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
Depot *d;
|
|
|
TileIndex tile = TileVirtXY(x, y);
|
|
|
int32 cost, ret;
|
|
|
uint tileh;
|
|
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
|
|
/* check railtype and valid direction for depot (0 through 3), 4 in total */
|
|
|
if (!ValParamRailtype(p1) || p2 > 3) return CMD_ERROR;
|
|
|
|
|
|
tileh = GetTileSlope(tile, NULL);
|
|
|
|
|
|
/* Prohibit construction if
|
|
|
The tile is non-flat AND
|
|
|
1) The AI is "old-school"
|
|
|
2) build-on-slopes is disabled
|
|
|
3) the tile is steep i.e. spans two height levels
|
|
|
4) the exit points in the wrong direction
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (tileh != 0 && (
|
|
|
_is_old_ai_player ||
|
|
|
!_patches.build_on_slopes ||
|
|
|
IsSteepTileh(tileh) ||
|
|
|
!CanBuildDepotByTileh(p2, tileh)
|
|
|
)
|
|
|
) {
|
|
|
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
|
|
|
}
|
|
|
|
|
|
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
if (CmdFailed(ret)) return CMD_ERROR;
|
|
|
cost = ret;
|
|
|
|
|
|
d = AllocateDepot();
|
|
|
if (d == NULL)
|
|
|
return CMD_ERROR;
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
if (_current_player == _local_player) _last_built_train_depot_tile = tile;
|
|
|
if (IsLocalPlayer()) _last_built_train_depot_tile = tile;
|
|
|
|
|
|
ModifyTile(tile,
|
|
|
MP_SETTYPE(MP_RAILWAY) |
|
|
|
MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5,
|
|
|
p1, /* map3_lo */
|
|
|
p2 | RAIL_TYPE_DEPOT_WAYPOINT /* map5 */
|
|
|
);
|
|
|
|
|
|
d->xy = tile;
|
|
|
d->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
|
|
|
|
|
|
SetSignalsOnBothDir(tile, (p2&1) ? 2 : 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
return cost + _price.build_train_depot;
|
|
|
}
|
|
|
|
|
|
/** Build signals, alternate between double/single, signal/semaphore,
|
|
|
* pre/exit/combo-signals, and what-else not
|
|
|
* @param x,y coordinates where signals is being built
|
|
|
* @param p1 various bitstuffed elements
|
|
|
* - p1 = (bit 0-2) - track-orientation, valid values: 0-5 (Track enum)
|
|
|
* - p1 = (bit 3) - choose semaphores/signals or cycle normal/pre/exit/combo depending on context
|
|
|
* @param p2 used for CmdBuildManySignals() to copy direction of first signal
|
|
|
* TODO: p2 should be replaced by two bits for "along" and "against" the track.
|
|
|
*/
|
|
|
int32 CmdBuildSingleSignal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
TileIndex tile = TileVirtXY(x, y);
|
|
|
bool semaphore;
|
|
|
bool pre_signal;
|
|
|
Track track = (Track)(p1 & 0x7);
|
|
|
byte m5;
|
|
|
int32 cost;
|
|
|
|
|
|
// Same bit, used in different contexts
|
|
|
semaphore = pre_signal = HASBIT(p1, 3);
|
|
|
|
|
|
if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicle(tile))
|
|
|
return CMD_ERROR;
|
|
|
|
|
|
/* Protect against invalid signal copying */
|
|
|
if (p2 != 0 && (p2 & SignalOnTrack(track)) == 0) return CMD_ERROR;
|
|
|
|
|
|
m5 = _m[tile].m5;
|
|
|
|
|
|
/* You can only build signals on plain rail tiles, and the selected track must exist */
|