(svn r24331) -Change [FS#5204]: [NewGRF] Make bounding boxes of road vehicles change according to the vehicle length to make alignment easier.

This commit is contained in:
frosch 2012-06-07 15:41:14 +00:00
parent 86b013f872
commit 4c79a06567
1 changed files with 17 additions and 12 deletions

View File

@ -389,23 +389,28 @@ void RoadVehicle::MarkDirty()
void RoadVehicle::UpdateDeltaXY(Direction direction) void RoadVehicle::UpdateDeltaXY(Direction direction)
{ {
static const int8 _delta_xy_table[8][4] = { static const int8 _delta_xy_table[8][10] = {
/* y_extent, x_extent, y_offs, x_offs */ /* y_extent, x_extent, y_offs, x_offs, y_bb_offs, x_bb_offs, y_extent_shorten, x_extent_shorten, y_bb_offs_shorten, x_bb_offs_shorten */
{3, 3, -1, -1}, // N {3, 3, -1, -1, 0, 0, -1, -1, -1, -1}, // N
{3, 7, -1, -3}, // NE {3, 7, -1, -3, 0, -1, 0, -1, 0, 0}, // NE
{3, 3, -1, -1}, // E {3, 3, -1, -1, 0, 0, 1, -1, 1, -1}, // E
{7, 3, -3, -1}, // SE {7, 3, -3, -1, -1, 0, 0, 0, 1, 0}, // SE
{3, 3, -1, -1}, // S {3, 3, -1, -1, 0, 0, 1, 1, 1, 1}, // S
{3, 7, -1, -3}, // SW {3, 7, -1, -3, 0, -1, 0, 0, 0, 1}, // SW
{3, 3, -1, -1}, // W {3, 3, -1, -1, 0, 0, -1, 1, -1, 1}, // W
{7, 3, -3, -1}, // NW {7, 3, -3, -1, -1, 0, -1, 0, 0, 0}, // NW
}; };
int shorten = VEHICLE_LENGTH - this->gcache.cached_veh_length;
if (!IsDiagonalDirection(direction)) shorten >>= 1;
const int8 *bb = _delta_xy_table[direction]; const int8 *bb = _delta_xy_table[direction];
this->x_bb_offs = bb[5] + bb[9] * shorten;
this->y_bb_offs = bb[4] + bb[8] * shorten;;
this->x_offs = bb[3]; this->x_offs = bb[3];
this->y_offs = bb[2]; this->y_offs = bb[2];
this->x_extent = bb[1]; this->x_extent = bb[1] + bb[7] * shorten;
this->y_extent = bb[0]; this->y_extent = bb[0] + bb[6] * shorten;
this->z_extent = 6; this->z_extent = 6;
} }