Changeset - r20231:ee3fa97a7874
[Not reviewed]
master
0 1 0
frosch - 11 years ago 2013-05-07 13:49:18
frosch@openttd.org
(svn r25231) -Fix (r25227): Also update infrastructure counts. (adf88)
1 file changed with 12 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -292,12 +292,13 @@ CommandCost CmdBuildBridge(TileIndex end
 
	/* Aqueducts can't be built of flat land. */
 
	if (transport_type == TRANSPORT_WATER && (tileh_start == SLOPE_FLAT || tileh_end == SLOPE_FLAT)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 
	if (z_start != z_end) return_cmd_error(STR_ERROR_BRIDGEHEADS_NOT_SAME_HEIGHT);
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	Owner owner;
 
	bool is_new_owner;
 
	if (IsBridgeTile(tile_start) && IsBridgeTile(tile_end) &&
 
			GetOtherBridgeEnd(tile_start) == tile_end &&
 
			GetTunnelBridgeTransportType(tile_start) == transport_type) {
 
		/* Replace a current bridge. */
 

	
 
		/* If this is a railway bridge, make sure the railtypes match. */
 
@@ -330,13 +331,14 @@ CommandCost CmdBuildBridge(TileIndex end
 
		}
 

	
 
		cost.AddCost((bridge_len + 1) * _price[PR_CLEAR_BRIDGE]); // The cost of clearing the current bridge.
 
		owner = GetTileOwner(tile_start);
 

	
 
		/* If bridge belonged to bankrupt company, it has a new owner now */
 
		if (owner == OWNER_NONE) owner = company;
 
		is_new_owner = (owner == OWNER_NONE);
 
		if (is_new_owner) owner = company;
 

	
 
		switch (transport_type) {
 
			case TRANSPORT_RAIL:
 
				/* Keep the reservation, the path stays valid. */
 
				pbs_reservation = HasTunnelBridgeReservation(tile_start);
 
				break;
 
@@ -438,31 +440,37 @@ CommandCost CmdBuildBridge(TileIndex end
 
				 * tile already has the has_bridge_above bits set. */
 
				SetBridgeMiddle(tile, direction);
 
			}
 
		}
 

	
 
		owner = company;
 
		is_new_owner = true;
 
	}
 

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

	
 
		Company *c = Company::GetIfValid(owner);
 
		switch (transport_type) {
 
			case TRANSPORT_RAIL:
 
				/* Add to company infrastructure count if building a new bridge. */
 
				if (!IsBridgeTile(tile_start) && c != NULL) c->infrastructure.rail[railtype] += (bridge_len + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
 
				/* Add to company infrastructure count if required. */
 
				if (is_new_owner && c != NULL) c->infrastructure.rail[railtype] += (bridge_len + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
 
				MakeRailBridgeRamp(tile_start, owner, bridge_type, dir,                 railtype);
 
				MakeRailBridgeRamp(tile_end,   owner, bridge_type, ReverseDiagDir(dir), railtype);
 
				SetTunnelBridgeReservation(tile_start, pbs_reservation);
 
				SetTunnelBridgeReservation(tile_end,   pbs_reservation);
 
				break;
 

	
 
			case TRANSPORT_ROAD: {
 
				RoadTypes prev_roadtypes = IsBridgeTile(tile_start) ? GetRoadTypes(tile_start) : ROADTYPES_NONE;
 
				if (is_new_owner) {
 
					/* Also give unowned present roadtypes to new owner */
 
					if (HasBit(prev_roadtypes, ROADTYPE_ROAD) && GetRoadOwner(tile_start, ROADTYPE_ROAD) == OWNER_NONE) ClrBit(prev_roadtypes, ROADTYPE_ROAD);
 
					if (HasBit(prev_roadtypes, ROADTYPE_TRAM) && GetRoadOwner(tile_start, ROADTYPE_TRAM) == OWNER_NONE) ClrBit(prev_roadtypes, ROADTYPE_TRAM);
 
				}
 
				if (c != NULL) {
 
					/* Add all new road types to the company infrastructure counter. */
 
					RoadType new_rt;
 
					FOR_EACH_SET_ROADTYPE(new_rt, roadtypes ^ prev_roadtypes) {
 
						/* A full diagonal road tile has two road bits. */
 
						Company::Get(owner)->infrastructure.road[new_rt] += (bridge_len + 2) * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
 
@@ -475,13 +483,13 @@ CommandCost CmdBuildBridge(TileIndex end
 
				MakeRoadBridgeRamp(tile_start, owner, owner_road, owner_tram, bridge_type, dir,                 roadtypes);
 
				MakeRoadBridgeRamp(tile_end,   owner, owner_road, owner_tram, bridge_type, ReverseDiagDir(dir), roadtypes);
 
				break;
 
			}
 

	
 
			case TRANSPORT_WATER:
 
				if (!IsBridgeTile(tile_start) && c != NULL) c->infrastructure.water += (bridge_len + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
 
				if (is_new_owner && c != NULL) c->infrastructure.water += (bridge_len + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
 
				MakeAqueductBridgeRamp(tile_start, owner, dir);
 
				MakeAqueductBridgeRamp(tile_end,   owner, ReverseDiagDir(dir));
 
				break;
 

	
 
			default:
 
				NOT_REACHED();
0 comments (0 inline, 0 general)