Exemple #1
0
        /**
         * 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);
        }
Exemple #2
0
/**
 * Clean up unnecessary RoadBits of a planed tile.
 * @param tile current tile
 * @param org_rb planed RoadBits
 * @return optimised RoadBits
 */
        RoadBits CleanUpRoadBits(TileIndex tile, RoadBits org_rb)
        {
            if (!TileMap.IsValidTile(tile))
            {
                return(RoadBits.ROAD_NONE);
            }
            for (DiagDirection dir = DiagDirection.DIAGDIR_BEGIN; dir < DiagDirection.DIAGDIR_END; dir++)
            {
                TileIndex neighbor_tile = TileAddByDiagDir(tile, dir);

                /* Get the Roadbit pointing to the neighbor_tile */
                RoadBits target_rb = DiagDirToRoadBits(dir);

                /* If the roadbit is in the current plan */
                if (org_rb & target_rb)
                {
                    bool           connective  = false;
                    const RoadBits mirrored_rb = MirrorRoadBits(target_rb);

                    if (TileMap.IsValidTile(neighbor_tile))
                    {
                        switch (TileMap.GetTileType(neighbor_tile))
                        {
                        /* Always connective ones */
                        case TileType.MP_CLEAR:
                        case TileType.MP_TREES:
                            connective = true;
                            break;

                        /* The conditionally connective ones */
                        case TileType.MP_TUNNELBRIDGE:
                        case TileType.MP_STATION:
                        case TileType.MP_ROAD:
                            if (IsNormalRoadTile(neighbor_tile))
                            {
                                /* Always connective */
                                connective = true;
                            }
                            else
                            {
                                const RoadBits neighbor_rb =
                                    GetAnyRoadBits(neighbor_tile, RoadType.ROADTYPE_ROAD) |
                                    GetAnyRoadBits(neighbor_tile, RoadType.ROADTYPE_TRAM);

                                /* Accept only connective tiles */
                                connective = (neighbor_rb & mirrored_rb) != RoadBits.ROAD_NONE;
                            }
                            break;

                        case TileType.MP_RAILWAY:
                            connective = IsPossibleCrossing(neighbor_tile, DiagDirToAxis(dir));
                            break;

                        case TileType.MP_WATER:
                            /* Check for real water tile */
                            connective = !WaterMap.IsWater(neighbor_tile);
                            break;

                        /* The definitely not connective ones */
                        default: break;
                        }
                    }

                    /* If the neighbor tile is inconnective, remove the planed road connection to it */
                    if (!connective)
                    {
                        org_rb ^= target_rb;
                    }
                }
            }

            return(org_rb);
        }