2746 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
2746 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
2747 } |
2747 } |
2748 |
2748 |
2749 static byte AfterSetTrainPos(Vehicle *v, bool new_tile) |
2749 static byte AfterSetTrainPos(Vehicle *v, bool new_tile) |
2750 { |
2750 { |
2751 byte new_z, old_z; |
2751 byte old_z = v->z_pos; |
2752 |
2752 v->z_pos = GetSlopeZ(v->x_pos, v->y_pos); |
2753 // need this hint so it returns the right z coordinate on bridges. |
|
2754 _get_z_hint = v->z_pos; |
|
2755 new_z = GetSlopeZ(v->x_pos, v->y_pos); |
|
2756 _get_z_hint = 0; |
|
2757 |
|
2758 old_z = v->z_pos; |
|
2759 v->z_pos = new_z; |
|
2760 |
2753 |
2761 if (new_tile) { |
2754 if (new_tile) { |
2762 CLRBIT(v->u.rail.flags, VRF_GOINGUP); |
2755 CLRBIT(v->u.rail.flags, VRF_GOINGUP); |
2763 CLRBIT(v->u.rail.flags, VRF_GOINGDOWN); |
2756 CLRBIT(v->u.rail.flags, VRF_GOINGDOWN); |
2764 |
2757 |
2765 if (new_z != old_z) { |
2758 if (v->u.rail.track == TRACK_BIT_X || v->u.rail.track == TRACK_BIT_Y) { |
2766 TileIndex tile = TileVirtXY(v->x_pos, v->y_pos); |
2759 /* Any track that isn't TRACK_BIT_X or TRACK_BIT_Y cannot be sloped. |
2767 |
2760 * To check whether the current tile is sloped, and in which |
2768 // XXX workaround, whole UP/DOWN detection needs overhaul |
2761 * direction it is sloped, we get the 'z' at the center of |
2769 if (!IsTunnelTile(tile)) { |
2762 * the tile (middle_z) and the edge of the tile (old_z), |
2770 SETBIT(v->u.rail.flags, (new_z > old_z) ? VRF_GOINGUP : VRF_GOINGDOWN); |
2763 * which we then can compare. */ |
|
2764 static const int HALF_TILE_SIZE = TILE_SIZE / 2; |
|
2765 static const int INV_TILE_SIZE_MASK = ~(TILE_SIZE - 1); |
|
2766 |
|
2767 byte middle_z = GetSlopeZ((v->x_pos & INV_TILE_SIZE_MASK) | HALF_TILE_SIZE, (v->y_pos & INV_TILE_SIZE_MASK) | HALF_TILE_SIZE); |
|
2768 |
|
2769 /* For some reason tunnel tiles are always given as sloped :( |
|
2770 * But they are not sloped... */ |
|
2771 if (middle_z != v->z_pos && !IsTunnelTile(TileVirtXY(v->x_pos, v->y_pos))) { |
|
2772 SETBIT(v->u.rail.flags, (middle_z > old_z) ? VRF_GOINGUP : VRF_GOINGDOWN); |
2771 } |
2773 } |
2772 } |
2774 } |
2773 } |
2775 } |
2774 |
2776 |
2775 VehiclePositionChanged(v); |
2777 VehiclePositionChanged(v); |