road_cmd.c
changeset 2085 ae9e92ffe168
parent 2074 f23dcde246da
child 2124 425fb490ae70
equal deleted inserted replaced
2084:d67790a49f78 2085:ae9e92ffe168
   320 };
   320 };
   321 
   321 
   322 
   322 
   323 static uint32 CheckRoadSlope(int tileh, byte *pieces, byte existing)
   323 static uint32 CheckRoadSlope(int tileh, byte *pieces, byte existing)
   324 {
   324 {
   325 	if (!(tileh & 0x10)) {
   325 	if (!IsSteepTileh(tileh)) {
   326 		byte road_bits = *pieces | existing;
   326 		byte road_bits = *pieces | existing;
   327 
   327 
   328 		// no special foundation
   328 		// no special foundation
   329 		if ((~_valid_tileh_slopes_road[0][tileh] & road_bits) == 0) {
   329 		if ((~_valid_tileh_slopes_road[0][tileh] & road_bits) == 0) {
   330 			// force that all bits are set when we have slopes
   330 			// force that all bits are set when we have slopes
   383 			goto do_clear;
   383 			goto do_clear;
   384 		}
   384 		}
   385 	} else if (ti.type == MP_RAILWAY) {
   385 	} else if (ti.type == MP_RAILWAY) {
   386 		byte m5;
   386 		byte m5;
   387 
   387 
   388 		if (ti.tileh & 0x10) // very steep tile
   388 		if (IsSteepTileh(ti.tile)) // very steep tile
   389 				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   389 				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   390 
   390 
   391 		if(!_valid_tileh_slopes_road[2][ti.tileh]) // prevent certain slopes
   391 		if(!_valid_tileh_slopes_road[2][ti.tileh]) // prevent certain slopes
   392 				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   392 				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   393 
   393 
   415 		}
   415 		}
   416 		return _price.build_road * 2;
   416 		return _price.build_road * 2;
   417 	} else if (ti.type == MP_TUNNELBRIDGE) {
   417 	} else if (ti.type == MP_TUNNELBRIDGE) {
   418 
   418 
   419 		/* check for flat land */
   419 		/* check for flat land */
   420 		if (ti.tileh & 0x10) // very steep tile
   420 		if (IsSteepTileh(ti.tileh)) // very steep tile
   421 				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   421 				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   422 
   422 
   423 		/* is this middle part of a bridge? */
   423 		/* is this middle part of a bridge? */
   424 		if ((ti.map5 & 0xC0) != 0xC0)
   424 		if ((ti.map5 & 0xC0) != 0xC0)
   425 				goto do_clear;
   425 				goto do_clear;
   618 
   618 
   619 /** Build a road depot.
   619 /** Build a road depot.
   620  * @param x,y tile coordinates where the depot will be built
   620  * @param x,y tile coordinates where the depot will be built
   621  * @param p1 depot direction (0 through 3), where 0 is NW, 1 is NE, etc.
   621  * @param p1 depot direction (0 through 3), where 0 is NW, 1 is NE, etc.
   622  * @param p2 unused
   622  * @param p2 unused
       
   623  *
       
   624  * @todo When checking for the tile slope,
       
   625  * distingush between "Flat land required" and "land sloped in wrong direction"
   623  */
   626  */
   624 int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
   627 int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
   625 {
   628 {
   626 	TileInfo ti;
   629 	TileInfo ti;
   627 	int32 cost;
   630 	int32 cost;
   637 	tile = ti.tile;
   640 	tile = ti.tile;
   638 
   641 
   639 	if (!EnsureNoVehicle(tile))
   642 	if (!EnsureNoVehicle(tile))
   640 		return CMD_ERROR;
   643 		return CMD_ERROR;
   641 
   644 
   642 	if (ti.tileh != 0) {
   645 	if ((ti.tileh != 0) && (
   643 		if (!_patches.build_on_slopes || (ti.tileh & 0x10 || !((0x4C >> p1) & ti.tileh) ))
   646 			!_patches.build_on_slopes ||
       
   647 			IsSteepTileh(ti.tileh) ||
       
   648 			!CanBuildDepotByTileh(p1, ti.tileh)
       
   649 		)
       
   650 	) {
   644 			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
   651 			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
   645 	}
   652 	}
   646 
   653 
   647 	cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   654 	cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   648 	if (CmdFailed(cost)) return CMD_ERROR;
   655 	if (CmdFailed(cost)) return CMD_ERROR;