src/road_cmd.cpp
changeset 8012 51288087bccd
parent 7990 70039e33e893
child 8032 0901aabd9aef
equal deleted inserted replaced
8011:8e95362021d5 8012:51288087bccd
    31 #include "newgrf.h"
    31 #include "newgrf.h"
    32 #include "station_map.h"
    32 #include "station_map.h"
    33 #include "tunnel_map.h"
    33 #include "tunnel_map.h"
    34 #include "misc/autoptr.hpp"
    34 #include "misc/autoptr.hpp"
    35 
    35 
    36 
       
    37 static uint CountRoadBits(RoadBits r)
       
    38 {
       
    39 	uint count = 0;
       
    40 
       
    41 	if (r & ROAD_NW) ++count;
       
    42 	if (r & ROAD_SW) ++count;
       
    43 	if (r & ROAD_SE) ++count;
       
    44 	if (r & ROAD_NE) ++count;
       
    45 	return count;
       
    46 }
       
    47 
       
    48 
       
    49 bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, bool *edge_road, RoadType rt)
    36 bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, bool *edge_road, RoadType rt)
    50 {
    37 {
    51 	RoadBits present;
    38 	RoadBits present;
    52 	RoadBits n;
    39 	RoadBits n;
    53 	*edge_road = true;
    40 	*edge_road = true;
   223 					if (rt != ROADTYPE_TRAM) SetDisallowedRoadDirections(tile, DRD_NONE);
   210 					if (rt != ROADTYPE_TRAM) SetDisallowedRoadDirections(tile, DRD_NONE);
   224 					SetRoadBits(tile, present, rt);
   211 					SetRoadBits(tile, present, rt);
   225 					MarkTileDirtyByTile(tile);
   212 					MarkTileDirtyByTile(tile);
   226 				}
   213 				}
   227 			}
   214 			}
   228 			return CommandCost(CountRoadBits(c) * _price.remove_road);
   215 			return CommandCost(COUNTBITS(c) * _price.remove_road);
   229 		}
   216 		}
   230 
   217 
   231 		case ROAD_TILE_CROSSING: {
   218 		case ROAD_TILE_CROSSING: {
   232 			if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) {
   219 			if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) {
   233 				return CMD_ERROR;
   220 				return CMD_ERROR;
   485 	if (IsTileType(tile, MP_ROAD)) {
   472 	if (IsTileType(tile, MP_ROAD)) {
   486 		/* Don't put the pieces that already exist */
   473 		/* Don't put the pieces that already exist */
   487 		pieces &= ComplementRoadBits(existing);
   474 		pieces &= ComplementRoadBits(existing);
   488 	}
   475 	}
   489 
   476 
   490 	cost.AddCost(CountRoadBits(pieces) * _price.build_road);
   477 	cost.AddCost(COUNTBITS(pieces) * _price.build_road);
   491 	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
   478 	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
   492 		/* Pay for *every* tile of the bridge or tunnel */
   479 		/* Pay for *every* tile of the bridge or tunnel */
   493 		cost.MultiplyCost(DistanceManhattan(IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile), tile));
   480 		cost.MultiplyCost(DistanceManhattan(IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile), tile));
   494 	}
   481 	}
   495 
   482