src/ai/default/default.cpp
changeset 7866 e19fda04e8d3
parent 7813 49fbe41f8a04
child 7883 7777bca58ae0
equal deleted inserted replaced
7865:b00756560b9d 7866:e19fda04e8d3
  1689 			}
  1689 			}
  1690 
  1690 
  1691 			/* signals too? */
  1691 			/* signals too? */
  1692 			if (j & 3) {
  1692 			if (j & 3) {
  1693 				// Can't build signals on a road.
  1693 				// Can't build signals on a road.
  1694 				if (IsTileType(c, MP_STREET)) return CMD_ERROR;
  1694 				if (IsTileType(c, MP_ROAD)) return CMD_ERROR;
  1695 
  1695 
  1696 				if (flag & DC_EXEC) {
  1696 				if (flag & DC_EXEC) {
  1697 					j = 4 - j;
  1697 					j = 4 - j;
  1698 					do {
  1698 					do {
  1699 						ret = DoCommand(c, k, 0, flag, CMD_BUILD_SIGNALS);
  1699 						ret = DoCommand(c, k, 0, flag, CMD_BUILD_SIGNALS);
  2042 
  2042 
  2043 			if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile_new, NULL) != SLOPE_FLAT) {
  2043 			if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile_new, NULL) != SLOPE_FLAT) {
  2044 				if (!flag) return;
  2044 				if (!flag) return;
  2045 				break;
  2045 				break;
  2046 			}
  2046 			}
  2047 			if (type != MP_WATER && type != MP_RAILWAY && type != MP_STREET) return;
  2047 			if (type != MP_WATER && type != MP_RAILWAY && type != MP_ROAD) return;
  2048 			flag = true;
  2048 			flag = true;
  2049 		}
  2049 		}
  2050 
  2050 
  2051 		// Is building a (rail)bridge possible at this place (type doesn't matter)?
  2051 		// Is building a (rail)bridge possible at this place (type doesn't matter)?
  2052 		if (CmdFailed(DoCommand(tile_new, tile, 0 | arf->player->ai.railtype_to_use << 8, DC_AUTO, CMD_BUILD_BRIDGE))) {
  2052 		if (CmdFailed(DoCommand(tile_new, tile, 0 | arf->player->ai.railtype_to_use << 8, DC_AUTO, CMD_BUILD_BRIDGE))) {
  2637 		TileIndex c = TILE_MASK(tile + ToTileIndexDiff(p->tileoffs));
  2637 		TileIndex c = TILE_MASK(tile + ToTileIndexDiff(p->tileoffs));
  2638 
  2638 
  2639 		_cleared_town = NULL;
  2639 		_cleared_town = NULL;
  2640 
  2640 
  2641 		if (p->mode == 2) {
  2641 		if (p->mode == 2) {
  2642 			if (IsTileType(c, MP_STREET) &&
  2642 			if (IsTileType(c, MP_ROAD) &&
  2643 					GetRoadTileType(c) == ROAD_TILE_NORMAL &&
  2643 					GetRoadTileType(c) == ROAD_TILE_NORMAL &&
  2644 					(GetRoadBits(c, ROADTYPE_ROAD) & p->attr) != 0) {
  2644 					(GetRoadBits(c, ROADTYPE_ROAD) & p->attr) != 0) {
  2645 				roadflag |= 2;
  2645 				roadflag |= 2;
  2646 
  2646 
  2647 				// all bits are already built?
  2647 				// all bits are already built?
  2680 		} else if (p->mode == 3) {
  2680 		} else if (p->mode == 3) {
  2681 			if (flag & DC_EXEC) continue;
  2681 			if (flag & DC_EXEC) continue;
  2682 
  2682 
  2683 			if (GetTileSlope(c, NULL) != SLOPE_FLAT) return CMD_ERROR;
  2683 			if (GetTileSlope(c, NULL) != SLOPE_FLAT) return CMD_ERROR;
  2684 
  2684 
  2685 			if (!IsTileType(c, MP_STREET) || GetRoadTileType(c) != ROAD_TILE_NORMAL) {
  2685 			if (!IsTileType(c, MP_ROAD) || GetRoadTileType(c) != ROAD_TILE_NORMAL) {
  2686 				ret = DoCommand(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR);
  2686 				ret = DoCommand(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR);
  2687 				if (CmdFailed(ret)) return CMD_ERROR;
  2687 				if (CmdFailed(ret)) return CMD_ERROR;
  2688 			}
  2688 			}
  2689 
  2689 
  2690 		}
  2690 		}
  2855 	uint dist = DistanceManhattan(tile, a->dest);
  2855 	uint dist = DistanceManhattan(tile, a->dest);
  2856 
  2856 
  2857 	if (dist <= a->best_dist) {
  2857 	if (dist <= a->best_dist) {
  2858 		TileIndex tile2 = TILE_MASK(tile + TileOffsByDiagDir(_dir_by_track[track]));
  2858 		TileIndex tile2 = TILE_MASK(tile + TileOffsByDiagDir(_dir_by_track[track]));
  2859 
  2859 
  2860 		if (IsTileType(tile2, MP_STREET) && GetRoadTileType(tile2) == ROAD_TILE_NORMAL) {
  2860 		if (IsTileType(tile2, MP_ROAD) && GetRoadTileType(tile2) == ROAD_TILE_NORMAL) {
  2861 			a->best_dist = dist;
  2861 			a->best_dist = dist;
  2862 			a->best_tile = tile;
  2862 			a->best_tile = tile;
  2863 			a->best_track = track;
  2863 			a->best_track = track;
  2864 		}
  2864 		}
  2865 	}
  2865 	}
  2943 				// Allow a bridge if either we have a tile that's water, rail or street,
  2943 				// Allow a bridge if either we have a tile that's water, rail or street,
  2944 				// or if we found an up tile.
  2944 				// or if we found an up tile.
  2945 				if (!flag) return;
  2945 				if (!flag) return;
  2946 				break;
  2946 				break;
  2947 			}
  2947 			}
  2948 			if (type != MP_WATER && type != MP_RAILWAY && type != MP_STREET) return;
  2948 			if (type != MP_WATER && type != MP_RAILWAY && type != MP_ROAD) return;
  2949 			flag = true;
  2949 			flag = true;
  2950 		}
  2950 		}
  2951 
  2951 
  2952 		// Is building a (rail)bridge possible at this place (type doesn't matter)?
  2952 		// Is building a (rail)bridge possible at this place (type doesn't matter)?
  2953 		if (CmdFailed(DoCommand(tile_new, tile, ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE)))
  2953 		if (CmdFailed(DoCommand(tile_new, tile, ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE)))
  3724 			if (GetRailTrackStatus(tile + TileOffsByDiagDir(dir)) & _depot_bits[dir])
  3724 			if (GetRailTrackStatus(tile + TileOffsByDiagDir(dir)) & _depot_bits[dir])
  3725 				return;
  3725 				return;
  3726 
  3726 
  3727 			DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
  3727 			DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
  3728 		}
  3728 		}
  3729 	} else if (IsTileType(tile, MP_STREET)) {
  3729 	} else if (IsTileType(tile, MP_ROAD)) {
  3730 		if (!IsTileOwner(tile, _current_player)) return;
  3730 		if (!IsTileOwner(tile, _current_player)) return;
  3731 
  3731 
  3732 		if (IsLevelCrossing(tile)) goto is_rail_crossing;
  3732 		if (IsLevelCrossing(tile)) goto is_rail_crossing;
  3733 
  3733 
  3734 		if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) {
  3734 		if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) {