Changeset - r12548:5e7f6e787227
[Not reviewed]
master
0 1 0
yexo - 15 years ago 2009-07-30 19:51:29
yexo@openttd.org
(svn r16996) -Fix (r16995): the tiles under the bridge were not marked dirty when a bridge was replaced with another type
1 file changed with 9 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -328,129 +328,135 @@ CommandCost CmdBuildBridge(TileIndex end
 
			}
 
		}
 

	
 
		TileIndexDiff delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
 
		for (TileIndex tile = tile_start + delta; tile != tile_end; tile += delta) {
 
			if (GetTileMaxZ(tile) > z_start) return_cmd_error(STR_BRIDGE_TOO_LOW_FOR_TERRAIN);
 

	
 
			if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) {
 
				/* Disallow crossing bridges for the time being */
 
				return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 
			}
 

	
 
			switch (GetTileType(tile)) {
 
				case MP_WATER:
 
					if (!IsWater(tile) && !IsCoast(tile)) goto not_valid_below;
 
					break;
 

	
 
				case MP_RAILWAY:
 
					if (!IsPlainRail(tile)) goto not_valid_below;
 
					break;
 

	
 
				case MP_ROAD:
 
					if (IsRoadDepot(tile)) goto not_valid_below;
 
					break;
 

	
 
				case MP_TUNNELBRIDGE:
 
					if (IsTunnel(tile)) break;
 
					if (direction == DiagDirToAxis(GetTunnelBridgeDirection(tile))) goto not_valid_below;
 
					if (z_start < GetBridgeHeight(tile)) goto not_valid_below;
 
					break;
 

	
 
				case MP_UNMOVABLE:
 
					if (!IsOwnedLand(tile)) goto not_valid_below;
 
					break;
 

	
 
				case MP_CLEAR:
 
					break;
 

	
 
				default:
 
	not_valid_below:;
 
					/* try and clear the middle landscape */
 
					ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
					if (CmdFailed(ret)) return ret;
 
					cost.AddCost(ret);
 
					break;
 
			}
 

	
 
			if (flags & DC_EXEC) {
 
				/* We do this here because when replacing a bridge with another
 
				 * type calling SetBridgeMiddle isn't needed. After all, the
 
				 * tile alread has the has_bridge_above bits set. */
 
				SetBridgeMiddle(tile, direction);
 
				MarkTileDirtyByTile(tile);
 
			}
 
		}
 

	
 
		owner = _current_company;
 
	}
 

	
 
	/* do the drill? */
 
	if (flags & DC_EXEC) {
 
		DiagDirection dir = AxisToDiagDir(direction);
 

	
 
		switch (transport_type) {
 
			case TRANSPORT_RAIL:
 
				MakeRailBridgeRamp(tile_start, owner, bridge_type, dir,                 railtype);
 
				MakeRailBridgeRamp(tile_end,   owner, bridge_type, ReverseDiagDir(dir), railtype);
 
				break;
 

	
 
			case TRANSPORT_ROAD:
 
				MakeRoadBridgeRamp(tile_start, owner, bridge_type, dir,                 roadtypes);
 
				MakeRoadBridgeRamp(tile_end,   owner, bridge_type, ReverseDiagDir(dir), roadtypes);
 
				break;
 

	
 
			case TRANSPORT_WATER:
 
				MakeAqueductBridgeRamp(tile_start, owner, dir);
 
				MakeAqueductBridgeRamp(tile_end,   owner, ReverseDiagDir(dir));
 
				break;
 

	
 
			default:
 
				NOT_REACHED();
 
		}
 
		MarkTileDirtyByTile(tile_start);
 
		MarkTileDirtyByTile(tile_end);
 

	
 
		/* Mark all tiles dirty */
 
		TileIndexDiff delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
 
		for (TileIndex tile = tile_start; tile <= tile_end; tile += delta) {
 
			MarkTileDirtyByTile(tile);
 
		}
 
	}
 

	
 
	if ((flags & DC_EXEC) && transport_type == TRANSPORT_RAIL) {
 
		Track track = AxisToTrack(direction);
 
		AddSideToSignalBuffer(tile_start, INVALID_DIAGDIR, _current_company);
 
		YapfNotifyTrackLayoutChange(tile_start, track);
 
	}
 

	
 
	/* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST)
 
	 * It's unnecessary to execute this command every time for every bridge. So it is done only
 
	 * and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated
 
	 */
 
	Company *c = Company::GetIfValid(_current_company);
 
	if (!(flags & DC_QUERY_COST) || (c != NULL && c->is_ai)) {
 
		bridge_len += 2; // begin and end tiles/ramps
 

	
 
		if (c != NULL) bridge_len = CalcBridgeLenCostFactor(bridge_len);
 

	
 
		cost.AddCost((int64)bridge_len * _price.build_bridge * GetBridgeSpec(bridge_type)->price >> 8);
 

	
 
		/* Aqueducts are a little more expensive. */
 
		if (transport_type == TRANSPORT_WATER) cost.AddCost((int64)bridge_len * _price.clear_water);
 
	}
 

	
 
	return cost;
 
}
 

	
 

	
 
/** Build Tunnel.
 
 * @param start_tile start tile of tunnel
 
 * @param flags type of operation
 
 * @param p1 railtype or roadtypes. bit 9 set means road tunnel
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	TransportType transport_type = (TransportType)GB(p1, 9, 1);
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	_build_tunnel_endtile = 0;
 
	if (transport_type == TRANSPORT_RAIL) {
 
		if (!ValParamRailtype((RailType)p1)) return CMD_ERROR;
 
	} else {
 
		const RoadTypes rts = (RoadTypes)GB(p1, 0, 2);
 
		if (!AreValidRoadTypes(rts) || !HasRoadTypesAvail(_current_company, rts)) return CMD_ERROR;
 
	}
 

	
 
	uint start_z;
0 comments (0 inline, 0 general)