src/town_cmd.cpp
changeset 7979 f0a24809ca93
parent 7978 0782afa40e4a
child 7990 70039e33e893
equal deleted inserted replaced
7978:0782afa40e4a 7979:f0a24809ca93
   645  * @param dir target direction
   645  * @param dir target direction
   646  * @param dist_multi distance multiplyer
   646  * @param dist_multi distance multiplyer
   647  * @return true if one of the neighboring tiles at the
   647  * @return true if one of the neighboring tiles at the
   648  *  given distance is a road tile else
   648  *  given distance is a road tile else
   649  */
   649  */
   650 static bool NeighborIsRoadTile(TileIndex tile, int dir, RoadBlockTitleDistance dist_multi)
   650 static bool IsNeighborRoadTile(TileIndex tile, int dir, RoadBlockTitleDistance dist_multi)
   651 {
   651 {
   652 	return (HASBIT(GetTownRoadMask(TILE_ADD(tile, dist_multi * ToTileIndexDiff(_roadblock_tileadd[dir + 1]))), dir ^ 2) ||
   652 	return (HASBIT(GetTownRoadMask(TILE_ADD(tile, dist_multi * ToTileIndexDiff(_roadblock_tileadd[dir + 1]))), dir ^ 2) ||
   653 			HASBIT(GetTownRoadMask(TILE_ADD(tile, dist_multi * ToTileIndexDiff(_roadblock_tileadd[dir + 3]))), dir ^ 2) ||
   653 			HASBIT(GetTownRoadMask(TILE_ADD(tile, dist_multi * ToTileIndexDiff(_roadblock_tileadd[dir + 3]))), dir ^ 2) ||
   654 			HASBIT(GetTownRoadMask(TILE_ADD(tile, dist_multi * (ToTileIndexDiff(_roadblock_tileadd[dir + 1]) + ToTileIndexDiff(_roadblock_tileadd[dir + 2])))), dir) ||
   654 			HASBIT(GetTownRoadMask(TILE_ADD(tile, dist_multi * (ToTileIndexDiff(_roadblock_tileadd[dir + 1]) + ToTileIndexDiff(_roadblock_tileadd[dir + 2])))), dir) ||
   655 			HASBIT(GetTownRoadMask(TILE_ADD(tile, dist_multi * (ToTileIndexDiff(_roadblock_tileadd[dir + 3]) + ToTileIndexDiff(_roadblock_tileadd[dir + 2])))), dir));
   655 			HASBIT(GetTownRoadMask(TILE_ADD(tile, dist_multi * (ToTileIndexDiff(_roadblock_tileadd[dir + 3]) + ToTileIndexDiff(_roadblock_tileadd[dir + 2])))), dir));
   683 			/* Tile has no slope */
   683 			/* Tile has no slope */
   684 			switch (_patches.town_layout) {
   684 			switch (_patches.town_layout) {
   685 				default: NOT_REACHED();
   685 				default: NOT_REACHED();
   686 
   686 
   687 				case TL_ORIGINAL: /* Disallow the road if any neighboring tile has a road (distance: 1) */
   687 				case TL_ORIGINAL: /* Disallow the road if any neighboring tile has a road (distance: 1) */
   688 					return !NeighborIsRoadTile(tile, dir, RB_TILE_DIST1);
   688 					return !IsNeighborRoadTile(tile, dir, RB_TILE_DIST1);
   689 
   689 
   690 				case TL_BETTER_ROADS: /* Disallow the road if any neighboring tile has a road (distance: 1 and 2). */
   690 				case TL_BETTER_ROADS: /* Disallow the road if any neighboring tile has a road (distance: 1 and 2). */
   691 					return !(NeighborIsRoadTile(tile, dir, RB_TILE_DIST1) ||
   691 					return !(IsNeighborRoadTile(tile, dir, RB_TILE_DIST1) ||
   692 							NeighborIsRoadTile(tile, dir, RB_TILE_DIST2));
   692 							IsNeighborRoadTile(tile, dir, RB_TILE_DIST2));
   693 			}
   693 			}
   694 		}
   694 		}
   695 
   695 
   696 		/* If the tile is not a slope in the right direction, then
   696 		/* If the tile is not a slope in the right direction, then
   697 		 * maybe terraform some. */
   697 		 * maybe terraform some. */
   828  *
   828  *
   829  * @param tile current tile
   829  * @param tile current tile
   830  * @return true if there are more than 2 house tiles next
   830  * @return true if there are more than 2 house tiles next
   831  *  to the current one
   831  *  to the current one
   832  */
   832  */
   833 static bool NeighborsAreHouseTiles(TileIndex tile)
   833 static bool AreNeighborsHouseTiles(TileIndex tile)
   834 {
   834 {
   835 	uint counter = 0; ///< counts the house neighbor tiles
   835 	uint counter = 0; ///< counts the house neighbor tiles
   836 
   836 
   837 	/* We can't look further than that. */
   837 	/* We can't look further than that. */
   838 	if (TileX(tile) < 1 || TileY(tile) < 1) {
   838 	if (TileX(tile) < 1 || TileY(tile) < 1) {
   998 				break;
   998 				break;
   999 
   999 
  1000 			case TL_3X3_GRID: /* Use 2x2 grid afterwards! */
  1000 			case TL_3X3_GRID: /* Use 2x2 grid afterwards! */
  1001 				/* Fill gap if house has enougth neighbors */
  1001 				/* Fill gap if house has enougth neighbors */
  1002 				tmptile2 = TILE_ADD(tmptile, ToTileIndexDiff(_roadblock_tileadd[i]));
  1002 				tmptile2 = TILE_ADD(tmptile, ToTileIndexDiff(_roadblock_tileadd[i]));
  1003 				if (NeighborsAreHouseTiles(tmptile2) && BuildTownHouse(t1, tmptile2)) {
  1003 				if (AreNeighborsHouseTiles(tmptile2) && BuildTownHouse(t1, tmptile2)) {
  1004 					_grow_town_result = -1;
  1004 					_grow_town_result = -1;
  1005 				}
  1005 				}
  1006 
  1006 
  1007 			case TL_2X2_GRID:
  1007 			case TL_2X2_GRID:
  1008 				rcmd = GetTownRoadGridElement(t1, tmptile);
  1008 				rcmd = GetTownRoadGridElement(t1, tmptile);
  1010 				break;
  1010 				break;
  1011 
  1011 
  1012 			case TL_BETTER_ROADS: /* Use original afterwards! */
  1012 			case TL_BETTER_ROADS: /* Use original afterwards! */
  1013 				/* Fill gap if house has enougth neighbors */
  1013 				/* Fill gap if house has enougth neighbors */
  1014 				tmptile2 = TILE_ADD(tmptile, ToTileIndexDiff(_roadblock_tileadd[i]));
  1014 				tmptile2 = TILE_ADD(tmptile, ToTileIndexDiff(_roadblock_tileadd[i]));
  1015 				if (NeighborsAreHouseTiles(tmptile2) && BuildTownHouse(t1, tmptile2)) {
  1015 				if (AreNeighborsHouseTiles(tmptile2) && BuildTownHouse(t1, tmptile2)) {
  1016 					_grow_town_result = -1;
  1016 					_grow_town_result = -1;
  1017 				}
  1017 				}
  1018 
  1018 
  1019 			case TL_ORIGINAL:
  1019 			case TL_ORIGINAL:
  1020 				 /* Allow a house at the edge. 60% chance or
  1020 				 /* Allow a house at the edge. 60% chance or