src/station_cmd.cpp
changeset 6344 c5c1b17c8925
parent 6338 0fb4f452873c
child 6358 e7997742bf02
equal deleted inserted replaced
6343:56b8beb2ee6b 6344:c5c1b17c8925
  1248 /** Build a bus or truck stop
  1248 /** Build a bus or truck stop
  1249  * @param tile tile to build the stop at
  1249  * @param tile tile to build the stop at
  1250  * @param p1 entrance direction (DiagDirection)
  1250  * @param p1 entrance direction (DiagDirection)
  1251  * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
  1251  * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
  1252  *           bit 1: 0 for normal, 1 for drive-through
  1252  *           bit 1: 0 for normal, 1 for drive-through
  1253  *           bit 2: 0 for normal, 1 for build over road
       
  1254  *           bit 3: 0 for player owned road, 1 for town owned road
       
  1255  */
  1253  */
  1256 int32 CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
  1254 int32 CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
  1257 {
  1255 {
  1258 	Station *st;
  1256 	Station *st;
  1259 	RoadStop *road_stop;
  1257 	RoadStop *road_stop;
  1260 	int32 cost;
  1258 	int32 cost;
  1261 	int32 ret;
  1259 	int32 ret;
  1262 	bool type = HASBIT(p2, 0);
  1260 	bool type = HASBIT(p2, 0);
  1263 	bool is_drive_through = HASBIT(p2, 1);
  1261 	bool is_drive_through = HASBIT(p2, 1);
       
  1262 	bool build_over_road  = is_drive_through && IsTileType(tile, MP_STREET) && GetRoadTileType(tile) == ROAD_TILE_NORMAL;
  1264 	Owner cur_owner = _current_player;
  1263 	Owner cur_owner = _current_player;
  1265 
  1264 
  1266 	/* Saveguard the parameters */
  1265 	/* Saveguard the parameters */
  1267 	if (!IsValidDiagDirection((DiagDirection)p1)) return CMD_ERROR;
  1266 	if (!IsValidDiagDirection((DiagDirection)p1)) return CMD_ERROR;
  1268 	/* If it is a drive-through stop check for valid axis */
  1267 	/* If it is a drive-through stop check for valid axis */
  1269 	if (is_drive_through && !IsValidAxis((Axis)p1)) return CMD_ERROR;
  1268 	if (is_drive_through && !IsValidAxis((Axis)p1)) return CMD_ERROR;
  1270 	/* If overbuilding a road check tile is a valid road tile */
  1269 	/* Road bits in the wrong direction */
  1271 	if (HASBIT(p2, 2) && !(IsTileType(tile, MP_STREET) && GetRoadTileType(tile) == ROAD_TILE_NORMAL)) return CMD_ERROR;
  1270 	if (build_over_road && (GetRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return CMD_ERROR;
  1272 	/* If overbuilding a town road,check tile is town owned and patch setting is enabled */
  1271 	/* Not allowed to build over this road */
  1273 	if (HASBIT(p2, 3) && !(_patches.road_stop_on_town_road && IsTileOwner(tile, OWNER_TOWN))) return CMD_ERROR;
  1272 	if (build_over_road && !IsTileOwner(tile, _current_player) && !(IsTileOwner(tile, OWNER_TOWN) && _patches.road_stop_on_town_road)) return CMD_ERROR;
  1274 
  1273 
  1275 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
  1274 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
  1276 
  1275 
  1277 	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile))
  1276 	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile))
  1278 		return CMD_ERROR;
  1277 		return CMD_ERROR;
  1279 
  1278 
  1280 	if (is_drive_through & HASBIT(p2, 3)) _current_player = OWNER_TOWN;
  1279 	if (build_over_road && IsTileOwner(tile, OWNER_TOWN)) _current_player = OWNER_TOWN;
  1281 	ret = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL);
  1280 	ret = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL);
  1282 	_current_player = cur_owner;
  1281 	_current_player = cur_owner;
  1283 	if (CmdFailed(ret)) return ret;
  1282 	if (CmdFailed(ret)) return ret;
  1284 	cost = HASBIT(p2, 2) ? 0 : ret; // Don't add cost of clearing road when overbuilding
  1283 	cost = build_over_road ? 0 : ret; // Don't add cost of clearing road when overbuilding
  1285 
  1284 
  1286 	st = GetStationAround(tile, 1, 1, INVALID_STATION);
  1285 	st = GetStationAround(tile, 1, 1, INVALID_STATION);
  1287 	if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
  1286 	if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
  1288 
  1287 
  1289 	/* Find a station close to us */
  1288 	/* Find a station close to us */