src/rail_cmd.cpp
changeset 8909 fa15e9afad2f
parent 8894 1e5b2d4380b8
child 8910 b261b6cb9b21
equal deleted inserted replaced
8908:6163a06e60f8 8909:fa15e9afad2f
   237 				if (tileh == SLOPE_W) return HalftileFoundation(CORNER_W);
   237 				if (tileh == SLOPE_W) return HalftileFoundation(CORNER_W);
   238 				if (tileh == SLOPE_E) return HalftileFoundation(CORNER_E);
   238 				if (tileh == SLOPE_E) return HalftileFoundation(CORNER_E);
   239 				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
   239 				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
   240 
   240 
   241 			case TRACK_BIT_X:
   241 			case TRACK_BIT_X:
   242 				if (HasSlopeHighestCorner(tileh)) return FOUNDATION_INCLINED_X;
   242 				if (IsSlopeWithOneCornerRaised(tileh)) return FOUNDATION_INCLINED_X;
   243 				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
   243 				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
   244 
   244 
   245 			case TRACK_BIT_Y:
   245 			case TRACK_BIT_Y:
   246 				if (HasSlopeHighestCorner(tileh)) return FOUNDATION_INCLINED_Y;
   246 				if (IsSlopeWithOneCornerRaised(tileh)) return FOUNDATION_INCLINED_Y;
   247 				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
   247 				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
   248 
   248 
   249 			default:
   249 			default:
   250 				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
   250 				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
   251 		}
   251 		}
   253 
   253 
   254 		/* Track must be at least valid on leveled foundation */
   254 		/* Track must be at least valid on leveled foundation */
   255 		if (!valid_on_leveled) return FOUNDATION_INVALID;
   255 		if (!valid_on_leveled) return FOUNDATION_INVALID;
   256 
   256 
   257 		/* If slope has three raised corners, build leveled foundation */
   257 		/* If slope has three raised corners, build leveled foundation */
   258 		if (HasSlopeHighestCorner(ComplementSlope(tileh))) return FOUNDATION_LEVELED;
   258 		if (IsSlopeWithThreeCornersRaised(tileh)) return FOUNDATION_LEVELED;
   259 
   259 
   260 		/* If neighboured corners of track_corner are lowered, build halftile foundation */
   260 		/* If neighboured corners of track_corner are lowered, build halftile foundation */
   261 		if ((tileh & SlopeWithThreeCornersRaised(OppositeCorner(track_corner))) == SlopeWithOneCornerRaised(track_corner)) return HalftileFoundation(track_corner);
   261 		if ((tileh & SlopeWithThreeCornersRaised(OppositeCorner(track_corner))) == SlopeWithOneCornerRaised(track_corner)) return HalftileFoundation(track_corner);
   262 
   262 
   263 		/* else special anti-zig-zag foundation */
   263 		/* else special anti-zig-zag foundation */
   394 				return_cmd_error(STR_1007_ALREADY_BUILT);
   394 				return_cmd_error(STR_1007_ALREADY_BUILT);
   395 			}
   395 			}
   396 			/* FALLTHROUGH */
   396 			/* FALLTHROUGH */
   397 
   397 
   398 		default:
   398 		default:
   399 			bool water_ground = IsTileType(tile, MP_WATER) && !IsSteepSlope(tileh) && HasSlopeHighestCorner(tileh);
   399 			bool water_ground = IsTileType(tile, MP_WATER) && IsSlopeWithOneCornerRaised(tileh);
   400 
   400 
   401 			ret = CheckRailSlope(tileh, trackbit, TRACK_BIT_NONE, tile);
   401 			ret = CheckRailSlope(tileh, trackbit, TRACK_BIT_NONE, tile);
   402 			if (CmdFailed(ret)) return ret;
   402 			if (CmdFailed(ret)) return ret;
   403 			cost.AddCost(ret);
   403 			cost.AddCost(ret);
   404 
   404 
   538 	if (GetRailGroundType(t) == RAIL_GROUND_WATER) return flooded;
   538 	if (GetRailGroundType(t) == RAIL_GROUND_WATER) return flooded;
   539 
   539 
   540 	Slope tileh = GetTileSlope(t, NULL);
   540 	Slope tileh = GetTileSlope(t, NULL);
   541 	TrackBits rail_bits = GetTrackBits(t);
   541 	TrackBits rail_bits = GetTrackBits(t);
   542 
   542 
   543 	if (!IsSteepSlope(tileh) && HasSlopeHighestCorner(tileh)) {
   543 	if (IsSlopeWithOneCornerRaised(tileh)) {
   544 		TrackBits lower_track = CornerToTrackBits(OppositeCorner(GetHighestSlopeCorner(tileh)));
   544 		TrackBits lower_track = CornerToTrackBits(OppositeCorner(GetHighestSlopeCorner(tileh)));
   545 
   545 
   546 		TrackBits to_remove = lower_track & rail_bits;
   546 		TrackBits to_remove = lower_track & rail_bits;
   547 		if (to_remove != 0) {
   547 		if (to_remove != 0) {
   548 			_current_player = OWNER_WATER;
   548 			_current_player = OWNER_WATER;
  1495 /**
  1495 /**
  1496  * Draw fence at eastern side of track.
  1496  * Draw fence at eastern side of track.
  1497  */
  1497  */
  1498 static void DrawTrackFence_NS_1(const TileInfo *ti)
  1498 static void DrawTrackFence_NS_1(const TileInfo *ti)
  1499 {
  1499 {
  1500 	int z = ti->z;
  1500 	uint z = ti->z + GetSlopeZInCorner(RemoveHalftileSlope(ti->tileh), CORNER_W);
  1501 	if (ti->tileh & SLOPE_W) z += TILE_HEIGHT;
       
  1502 	if (IsSteepSlope(ti->tileh)) z += TILE_HEIGHT;
       
  1503 	AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_VERT, _drawtile_track_palette,
  1501 	AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_VERT, _drawtile_track_palette,
  1504 		ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z);
  1502 		ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z);
  1505 }
  1503 }
  1506 
  1504 
  1507 /**
  1505 /**
  1508  * Draw fence at western side of track.
  1506  * Draw fence at western side of track.
  1509  */
  1507  */
  1510 static void DrawTrackFence_NS_2(const TileInfo *ti)
  1508 static void DrawTrackFence_NS_2(const TileInfo *ti)
  1511 {
  1509 {
  1512 	int z = ti->z;
  1510 	uint z = ti->z + GetSlopeZInCorner(RemoveHalftileSlope(ti->tileh), CORNER_E);
  1513 	if (ti->tileh & SLOPE_E) z += TILE_HEIGHT;
       
  1514 	if (IsSteepSlope(ti->tileh)) z += TILE_HEIGHT;
       
  1515 	AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_VERT, _drawtile_track_palette,
  1511 	AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_VERT, _drawtile_track_palette,
  1516 		ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z);
  1512 		ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z);
  1517 }
  1513 }
  1518 
  1514 
  1519 /**
  1515 /**
  1520  * Draw fence at southern side of track.
  1516  * Draw fence at southern side of track.
  1521  */
  1517  */
  1522 static void DrawTrackFence_WE_1(const TileInfo *ti)
  1518 static void DrawTrackFence_WE_1(const TileInfo *ti)
  1523 {
  1519 {
  1524 	int z = ti->z;
  1520 	uint z = ti->z + GetSlopeZInCorner(RemoveHalftileSlope(ti->tileh), CORNER_N);
  1525 	if (ti->tileh & SLOPE_N) z += TILE_HEIGHT;
       
  1526 	if (IsSteepSlope(ti->tileh)) z += TILE_HEIGHT;
       
  1527 	AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_HORZ, _drawtile_track_palette,
  1521 	AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_HORZ, _drawtile_track_palette,
  1528 		ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z);
  1522 		ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z);
  1529 }
  1523 }
  1530 
  1524 
  1531 /**
  1525 /**
  1532  * Draw fence at northern side of track.
  1526  * Draw fence at northern side of track.
  1533  */
  1527  */
  1534 static void DrawTrackFence_WE_2(const TileInfo *ti)
  1528 static void DrawTrackFence_WE_2(const TileInfo *ti)
  1535 {
  1529 {
  1536 	int z = ti->z;
  1530 	uint z = ti->z + GetSlopeZInCorner(RemoveHalftileSlope(ti->tileh), CORNER_S);
  1537 	if (ti->tileh & SLOPE_S) z += TILE_HEIGHT;
       
  1538 	if (IsSteepSlope(ti->tileh)) z += TILE_HEIGHT;
       
  1539 	AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_HORZ, _drawtile_track_palette,
  1531 	AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_HORZ, _drawtile_track_palette,
  1540 		ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z);
  1532 		ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z);
  1541 }
  1533 }
  1542 
  1534 
  1543 
  1535 
  2215 		/* Surface slope must not be changed */
  2207 		/* Surface slope must not be changed */
  2216 		default: return (((z_old != z_new) || (tileh_old != tileh_new)) ? CMD_ERROR : CommandCost(EXPENSES_CONSTRUCTION, _price.terraform));
  2208 		default: return (((z_old != z_new) || (tileh_old != tileh_new)) ? CMD_ERROR : CommandCost(EXPENSES_CONSTRUCTION, _price.terraform));
  2217 	}
  2209 	}
  2218 
  2210 
  2219 	/* The height of the track_corner must not be changed. The rest ensures GetRailFoundation() already. */
  2211 	/* The height of the track_corner must not be changed. The rest ensures GetRailFoundation() already. */
  2220 	z_old += GetSlopeZInCorner((Slope)(tileh_old & ~SLOPE_HALFTILE_MASK), track_corner);
  2212 	z_old += GetSlopeZInCorner(RemoveHalftileSlope(tileh_old), track_corner);
  2221 	z_new += GetSlopeZInCorner((Slope)(tileh_new & ~SLOPE_HALFTILE_MASK), track_corner);
  2213 	z_new += GetSlopeZInCorner(RemoveHalftileSlope(tileh_new), track_corner);
  2222 	if (z_old != z_new) return CMD_ERROR;
  2214 	if (z_old != z_new) return CMD_ERROR;
  2223 
  2215 
  2224 	CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
  2216 	CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
  2225 	/* Make the ground dirty, if surface slope has changed */
  2217 	/* Make the ground dirty, if surface slope has changed */
  2226 	if (tileh_old != tileh_new) {
  2218 	if (tileh_old != tileh_new) {