Changeset - r16046:d66d1b4228b3
[Not reviewed]
master
0 2 0
yexo - 14 years ago 2010-09-05 16:33:32
yexo@openttd.org
(svn r20749) -Fix: allow overbuilding objects with buoys and ship depots
2 files changed with 25 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/water_cmd.cpp
Show inline comments
 
@@ -91,56 +91,66 @@ static void MarkCanalsAndRiversAroundDir
 
 * @param flags type of operation
 
 * @param p1 bit 0 depot orientation (Axis)
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Axis axis = Extract<Axis, 0, 1>(p1);
 

	
 
	TileIndex tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
 

	
 
	if (!IsWaterTile(tile) || !IsWaterTile(tile2)) {
 
	if (!HasTileWaterClass(tile) || !IsTileOnWater(tile) || !HasTileWaterClass(tile2) || !IsTileOnWater(tile2)) {
 
		return_cmd_error(STR_ERROR_MUST_BE_BUILT_ON_WATER);
 
	}
 

	
 
	if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
	if (GetTileSlope(tile, NULL) != SLOPE_FLAT || GetTileSlope(tile2, NULL) != SLOPE_FLAT) {
 
		/* Prevent depots on rapids */
 
		return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
	}
 

	
 
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
 

	
 
	WaterClass wc1 = GetWaterClass(tile);
 
	WaterClass wc2 = GetWaterClass(tile2);
 
	CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_DEPOT_SHIP]);
 

	
 
	bool add_cost = !IsWaterTile(tile);
 
	CommandCost ret = DoCommand(tile, 0, 0, flags | DC_AUTO, CMD_LANDSCAPE_CLEAR);
 
	if (ret.Failed()) return ret;
 
	ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	if (add_cost) {
 
		cost.AddCost(ret);
 
	}
 
	add_cost = !IsWaterTile(tile2);
 
	ret = DoCommand(tile2, 0, 0, flags | DC_AUTO, CMD_LANDSCAPE_CLEAR);
 
	if (ret.Failed()) return ret;
 

	
 
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
 
	if (add_cost) {
 
		cost.AddCost(ret);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Depot *depot = new Depot(tile);
 
		depot->build_date = _date;
 

	
 
		MakeShipDepot(tile,  _current_company, depot->index, DEPOT_NORTH, axis, wc1);
 
		MakeShipDepot(tile2, _current_company, depot->index, DEPOT_SOUTH, axis, wc2);
 
		MarkTileDirtyByTile(tile);
 
		MarkTileDirtyByTile(tile2);
 
		MakeDefaultName(depot);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_DEPOT_SHIP]);
 
	return cost;
 
}
 

	
 
void MakeWaterKeepingClass(TileIndex tile, Owner o)
 
{
 
	WaterClass wc = GetWaterClass(tile);
 

	
 
	/* Autoslope might turn an originally canal or river tile into land */
 
	uint z;
 
	if (GetTileSlope(tile, &z) != SLOPE_FLAT) wc = WATER_CLASS_INVALID;
 

	
 
	if (wc == WATER_CLASS_SEA && z > 0) wc = WATER_CLASS_CANAL;
 

	
src/waypoint_cmd.cpp
Show inline comments
 
@@ -273,33 +273,40 @@ CommandCost CmdBuildRailWaypoint(TileInd
 

	
 
/**
 
 * Build a buoy.
 
 * @param tile tile where to place the bouy
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsWaterTile(tile) || tile == 0) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
	if (!HasTileWaterClass(tile) || !IsTileOnWater(tile) || tile == 0) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
	if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 

	
 
	/* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
 
	Waypoint *wp = FindDeletedWaypointCloseTo(tile, STR_SV_STNAME_BUOY, OWNER_NONE);
 
	if (wp == NULL && !Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_WAYPOINT_BUOY]);
 
	if (!IsWaterTile(tile)) {
 
		CommandCost ret = DoCommand(tile, 0, 0, flags | DC_AUTO, CMD_LANDSCAPE_CLEAR);
 
		if (ret.Failed()) return ret;
 
		cost.AddCost(ret);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		if (wp == NULL) {
 
			wp = new Waypoint(tile);
 
		} else {
 
			/* Move existing (recently deleted) buoy to the new location */
 
			wp->xy = tile;
 
			InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
 
		}
 
		wp->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
 

	
 
		wp->string_id = STR_SV_STNAME_BUOY;
 

	
 
@@ -307,25 +314,25 @@ CommandCost CmdBuildBuoy(TileIndex tile,
 
		wp->owner = OWNER_NONE;
 

	
 
		wp->build_date = _date;
 

	
 
		if (wp->town == NULL) MakeDefaultName(wp);
 

	
 
		MakeBuoy(tile, wp->index, GetWaterClass(tile));
 

	
 
		wp->UpdateVirtCoord();
 
		InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_WAYPOINT_BUOY]);
 
	return cost;
 
}
 

	
 
/**
 
 * Remove a buoy
 
 * @param tile TileIndex been queried
 
 * @param flags operation to perform
 
 * @pre IsBuoyTile(tile)
 
 * @return cost or failure of operation
 
 */
 
CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
 
{
 
	/* XXX: strange stuff, allow clearing as invalid company when clearing landscape */
0 comments (0 inline, 0 general)