mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-17 21:25:40 +00:00
Enable setting semaphore/electric type of signals on bridges/tunnels.
This commit is contained in:
parent
2b4dbf582a
commit
3861968765
@ -1056,21 +1056,39 @@ CommandCost CmdBuildSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
||||
TileIndex tile_exit = GetOtherTunnelBridgeEnd(tile);
|
||||
cost = CommandCost();
|
||||
bool flip_variant = false;
|
||||
if (!HasWormholeSignals(tile)) { // toggle signal zero costs.
|
||||
if (convert_signal) return_cmd_error(STR_ERROR_THERE_ARE_NO_SIGNALS);
|
||||
if (p2 != 12) cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_SIGNALS] * ((GetTunnelBridgeLength(tile, tile_exit) + 4) >> 2)); // minimal 1
|
||||
} else {
|
||||
if (HasBit(p1, 17)) return CommandCost();
|
||||
if (ctrl_pressed && !convert_signal) return CommandCost();
|
||||
if ((p2 != 0 && (sigvar == SIG_SEMAPHORE) != IsTunnelBridgeSemaphore(tile)) ||
|
||||
(convert_signal && (ctrl_pressed || (sigvar == SIG_SEMAPHORE) != IsTunnelBridgeSemaphore(tile)))) {
|
||||
flip_variant = true;
|
||||
cost = CommandCost(EXPENSES_CONSTRUCTION, (_price[PR_BUILD_SIGNALS] + _price[PR_CLEAR_SIGNALS]) *
|
||||
((GetTunnelBridgeLength(tile, tile_exit) + 4) >> 2)); // minimal 1
|
||||
}
|
||||
}
|
||||
if (flags & DC_EXEC) {
|
||||
if (p2 == 0 && HasWormholeSignals(tile)) { // Toggle signal if already signals present.
|
||||
if (IsTunnelBridgeEntrance(tile)) {
|
||||
ClrBitTunnelBridgeSignal(tile);
|
||||
ClrBitTunnelBridgeExit(tile_exit);
|
||||
SetBitTunnelBridgeExit(tile);
|
||||
SetBitTunnelBridgeSignal(tile_exit);
|
||||
if (convert_signal) {
|
||||
if (flip_variant) {
|
||||
SetTunnelBridgeSemaphore(tile, !IsTunnelBridgeSemaphore(tile));
|
||||
SetTunnelBridgeSemaphore(tile_exit, !IsTunnelBridgeSemaphore(tile_exit));
|
||||
}
|
||||
} else {
|
||||
ClrBitTunnelBridgeSignal(tile_exit);
|
||||
ClrBitTunnelBridgeExit(tile);
|
||||
SetBitTunnelBridgeExit(tile_exit);
|
||||
SetBitTunnelBridgeSignal(tile);
|
||||
if (IsTunnelBridgeEntrance(tile)) {
|
||||
ClrBitTunnelBridgeSignal(tile);
|
||||
ClrBitTunnelBridgeExit(tile_exit);
|
||||
SetBitTunnelBridgeExit(tile);
|
||||
SetBitTunnelBridgeSignal(tile_exit);
|
||||
} else {
|
||||
ClrBitTunnelBridgeSignal(tile_exit);
|
||||
ClrBitTunnelBridgeExit(tile);
|
||||
SetBitTunnelBridgeExit(tile_exit);
|
||||
SetBitTunnelBridgeSignal(tile);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Create one direction tunnel/bridge if required. */
|
||||
@ -1089,6 +1107,8 @@ CommandCost CmdBuildSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||
SetBitTunnelBridgeExit(tile);
|
||||
}
|
||||
}
|
||||
SetTunnelBridgeSemaphore(tile, sigvar == SIG_SEMAPHORE);
|
||||
SetTunnelBridgeSemaphore(tile_exit, sigvar == SIG_SEMAPHORE);
|
||||
}
|
||||
MarkBridgeOrTunnelDirty(tile);
|
||||
AddSideToSignalBuffer(tile, INVALID_DIAGDIR, GetTileOwner(tile));
|
||||
|
@ -1183,7 +1183,7 @@ static void DrawTunnelBridgeRampSignal(const TileInfo *ti)
|
||||
if (ti->tileh == SLOPE_FLAT && side != show_exit && dir == DIAGDIR_SW) z += 2;
|
||||
|
||||
if (ti->tileh != SLOPE_FLAT && IsBridge(ti->tile)) z += 8; // sloped bridge head
|
||||
SignalVariant variant = (_cur_year < _settings_client.gui.semaphore_build_before ? SIG_SEMAPHORE : SIG_ELECTRIC);
|
||||
SignalVariant variant = IsTunnelBridgeSemaphore(ti->tile) ? SIG_SEMAPHORE : SIG_ELECTRIC;
|
||||
|
||||
SpriteID sprite;
|
||||
if (variant == SIG_ELECTRIC) {
|
||||
@ -1233,7 +1233,7 @@ static void DrawBrigeSignalOnMiddelPart(const TileInfo *ti, TileIndex bridge_sta
|
||||
uint y = TileY(ti->tile) * TILE_SIZE + SignalPositions[side][position].y;
|
||||
z += 5;
|
||||
|
||||
SignalVariant variant = (_cur_year < _settings_client.gui.semaphore_build_before ? SIG_SEMAPHORE : SIG_ELECTRIC);
|
||||
SignalVariant variant = IsTunnelBridgeSemaphore(bridge_start_tile) ? SIG_SEMAPHORE : SIG_ELECTRIC;
|
||||
|
||||
SpriteID sprite;
|
||||
|
||||
|
@ -225,4 +225,16 @@ static inline void SetTunnelBridgeExitGreen(TileIndex t, bool green)
|
||||
SB(_me[t].m6, 0, 1, green ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline bool IsTunnelBridgeSemaphore(TileIndex t)
|
||||
{
|
||||
assert(IsTileType(t, MP_TUNNELBRIDGE) && HasWormholeSignals(t));
|
||||
return HasBit(_me[t].m6, 1);
|
||||
}
|
||||
|
||||
static inline void SetTunnelBridgeSemaphore(TileIndex t, bool is_semaphore)
|
||||
{
|
||||
assert(IsTileType(t, MP_TUNNELBRIDGE) && HasWormholeSignals(t));
|
||||
SB(_me[t].m6, 1, 1, is_semaphore ? 1 : 0);
|
||||
}
|
||||
|
||||
#endif /* TUNNELBRIDGE_MAP_H */
|
||||
|
Loading…
Reference in New Issue
Block a user