/** * Make a water lock. * @param t Tile to place the water lock section. * @param o Owner of the lock. * @param d Direction of the water lock. * @param wc_lower Original water class of the lower part. * @param wc_upper Original water class of the upper part. * @param wc_middle Original water class of the middle part. */ /*inline*/ public static void MakeLock(TileIndex t, Owner o, DiagDirection d, WaterClass wc_lower, WaterClass wc_upper, WaterClass wc_middle) { TileIndexDiff delta = Map.TileOffsByDiagDir(d); /* Keep the current waterclass and owner for the tiles. * It allows to restore them after the lock is deleted */ MakeLockTile(t, o, LockPart.LOCK_PART_MIDDLE, d, wc_middle); MakeLockTile((uint)(t - delta), IsWaterTile((uint)(t - delta)) ? TileMap.GetTileOwner((uint)(t - delta)) : o, LockPart.LOCK_PART_LOWER, d, wc_lower); MakeLockTile((uint)(t + delta), IsWaterTile((uint)(t + delta)) ? TileMap.GetTileOwner((uint)(t + delta)) : o, LockPart.LOCK_PART_UPPER, d, wc_upper); }
/** * Finds the end of a bridge in the specified direction starting at a middle tile * @param tile the bridge tile to find the bridge ramp for * @param dir the direction to search in */ public static TileIndex GetBridgeEnd(TileIndex tile, DiagDirection dir) { TileIndexDiff delta = Map.TileOffsByDiagDir(dir); dir = dir.ReverseDiagDir(); do { tile += (uint)delta.Difference; } while (!IsBridgeTile(tile) || GetTunnelBridgeDirection(tile) != dir); return(tile); }
/** * Is there a tunnel in the way in the given direction? * @param tile the tile to search from. * @param z the 'z' to search on. * @param dir the direction to start searching to. * @return true if and only if there is a tunnel. */ public static bool IsTunnelInWayDir(this TileIndex tile, int z, DiagDirection dir) { TileIndexDiff delta = TileOffsByDiagDir(dir); int height; do { tile -= delta; if (!TileMap.IsValidTile(tile)) { return(false); } height = TileMap.GetTileZ(tile); } while (z < height); return(z == height && IsTunnelTile(tile) && GetTunnelBridgeDirection(tile) == dir); }
/** * Gets the other end of the tunnel. Where a vehicle would reappear when it * enters at the given tile. * @param tile the tile to search from. * @return the tile of the other end of the tunnel. */ public static TileIndex GetOtherTunnelEnd(this TileIndex tile) { DiagDirection dir = GetTunnelBridgeDirection(tile); TileIndexDiff delta = TileOffsByDiagDir(dir); int z = TileMap.GetTileZ(tile); dir = ReverseDiagDir(dir); do { tile += delta; } while ( !IsTunnelTile(tile) || GetTunnelBridgeDirection(tile) != dir || TileMap.GetTileZ(tile) != z ); return(tile); }