Changeset - r16041:12e6e13120e4
[Not reviewed]
master
0 1 0
yexo - 14 years ago 2010-09-05 14:53:20
yexo@openttd.org
(svn r20744) -Fix: overbuilding an object with water under it failed
1 file changed with 6 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/object_cmd.cpp
Show inline comments
 
@@ -157,30 +157,31 @@ CommandCost CmdBuildObject(TileIndex til
 
	int size_x = GB(spec->size, 0, 4);
 
	int size_y = GB(spec->size, 4, 4);
 
	TileArea ta(tile, size_x, size_y);
 

	
 
	if (type == OBJECT_OWNED_LAND) {
 
		/* Owned land is special as it can be placed on any slope. */
 
		cost.AddCost(DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR));
 
	} else {
 
		/* Check the surface to build on. */
 
		bool allow_water = (spec->flags & (OBJECT_FLAG_BUILT_ON_WATER | OBJECT_FLAG_NOT_ON_LAND)) != 0;
 
		bool allow_ground = (spec->flags & OBJECT_FLAG_NOT_ON_LAND) == 0;
 
		TILE_AREA_LOOP(t, ta) {
 
			if (IsWaterTile(t)) {
 
			if (HasTileWaterClass(t) && IsTileOnWater(t)) {
 
				if (!allow_water) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
 
				/* For water tiles we want to "just" check whether the tile is water and
 
				 * can be cleared, i.e. it's not filled. We won't be paying though. */
 
				CommandCost ret = DoCommand(t, 0, 0, flags & ~(DC_EXEC | DC_NO_WATER), CMD_LANDSCAPE_CLEAR);
 
				if (ret.Failed()) return ret;
 
				if (!IsWaterTile(t)) {
 
					/* Normal water tiles don't have to be cleared. For all other tile types clear
 
					 * the tile but leave the water. */
 
					cost.AddCost(DoCommand(t, 0, 0, flags & ~DC_NO_WATER, CMD_LANDSCAPE_CLEAR));
 
				}
 
			} else {
 
				if (!allow_ground) return_cmd_error(STR_ERROR_MUST_BE_BUILT_ON_WATER);
 
				/* For non-water tiles, we'll have to clear it before building. */
 
				cost.AddCost(DoCommand(t, 0, 0, flags, CMD_LANDSCAPE_CLEAR));
 
			}
 
		}
 

	
 
		/* So, now the surface is checked... check the slope of said surface. */
 
		if (HasBit(spec->callback_mask, CBM_OBJ_SLOPE_CHECK)) {
 
			TILE_AREA_LOOP(t, ta) {
 
				TileIndex diff = t - tile;
 
				uint16 callback = GetObjectCallback(CBID_OBJECT_LAND_SLOPE_CHECK, GetTileSlope(t, NULL), TileY(diff) << 4 | TileX(diff), spec, NULL, t);
0 comments (0 inline, 0 general)