Changeset - r18156:39cce251f480
[Not reviewed]
master
0 1 0
yexo - 13 years ago 2011-10-04 20:18:12
yexo@openttd.org
(svn r22994) -Fix [FS#4775]: tile was cleared before the object-placement callback was run, resulting in possible differences in test and exec run
1 file changed with 19 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/object_cmd.cpp
Show inline comments
 
@@ -201,31 +201,33 @@ CommandCost CmdBuildObject(TileIndex til
 
	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. */
 
		/* Check the surface to build on. At this time we can't actually execute the
 
		 * the CLEAR_TILE commands since the newgrf callback later on can check
 
		 * some information about the tiles. */
 
		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 (HasTileWaterGround(t)) {
 
				if (!allow_water) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
 
				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));
 
					cost.AddCost(DoCommand(t, 0, 0, flags & ~DC_NO_WATER & ~DC_EXEC, CMD_LANDSCAPE_CLEAR));
 
				} else {
 
					/* Can't build on water owned by another company. */
 
					Owner o = GetTileOwner(t);
 
					if (o != OWNER_NONE && o != OWNER_WATER) cost.AddCost(CheckOwnership(o, t));
 
				}
 
			} 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));
 
				cost.AddCost(DoCommand(t, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR));
 
			}
 
		}
 

	
 
		/* So, now the surface is checked... check the slope of said surface. */
 
		int allowed_z;
 
		if (GetTileSlope(tile, (uint*)&allowed_z) != SLOPE_FLAT) allowed_z += TILE_HEIGHT;
 
@@ -241,12 +243,26 @@ CommandCost CmdBuildObject(TileIndex til
 
				cost.AddCost(CheckBuildableTile(t, 0, allowed_z, false, false));
 
			} else if (callback != 0) {
 
				/* The meaning of bit 10 is inverted in the result of this callback. */
 
				return GetErrorMessageFromLocationCallbackResult(ToggleBit(callback, 10), spec->grf_prop.grffile->grfid, STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 
			}
 
		}
 

	
 
		if (flags & DC_EXEC) {
 
			/* This is basically a copy of the loop above with the exception that we now
 
			 * execute the commands and don't check for errors, since that's already done. */
 
			TILE_AREA_LOOP(t, ta) {
 
				if (HasTileWaterGround(t)) {
 
					if (!IsWaterTile(t)) {
 
						DoCommand(t, 0, 0, (flags & ~DC_NO_WATER) | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR);
 
					}
 
				} else {
 
					DoCommand(t, 0, 0, flags | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR);
 
				}
 
			}
 
		}
 
	}
 
	if (cost.Failed()) return cost;
 

	
 
	/* Finally do a check for bridges. */
 
	TILE_AREA_LOOP(t, ta) {
 
		if (MayHaveBridgeAbove(t) && IsBridgeAbove(t) && (
0 comments (0 inline, 0 general)