Use CoordsXYZD on map_get_wall_element_at() (#10374)

* Use CoordsXYZD on map_get_wall_element_at()

* Add CoordsXYZ::ToTileStart()
This commit is contained in:
Tulio Leao 2019-12-18 07:23:54 -03:00 committed by Michael Steenbeek
parent 4f615c5802
commit af281817c3
5 changed files with 21 additions and 17 deletions

View File

@ -70,7 +70,7 @@ public:
return MakeResult(GA_ERROR::NOT_OWNED, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK);
}
auto wallElement = map_get_wall_element_at(_loc.x, _loc.y, _loc.z / 8, _loc.direction);
auto wallElement = map_get_wall_element_at(_loc);
if (wallElement == nullptr)
{
log_error(
@ -123,7 +123,7 @@ public:
res->Position.z = _loc.z;
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
auto wallElement = map_get_wall_element_at(_loc.x, _loc.y, _loc.z / 8, _loc.direction);
auto wallElement = map_get_wall_element_at(_loc);
if (wallElement == nullptr)
{
log_error(

View File

@ -7429,12 +7429,11 @@ static void vehicle_update_scenery_door(rct_vehicle* vehicle)
trackBlock++;
}
const rct_track_coordinates* trackCoordinates = &TrackCoordinates[trackType];
int32_t x = floor2(vehicle->x, 32);
int32_t y = floor2(vehicle->y, 32);
int32_t z = (vehicle->track_z - trackBlock->z + trackCoordinates->z_end) >> 3;
auto wallCoords = CoordsXYZ{ vehicle->x, vehicle->y, vehicle->track_z - trackBlock->z + trackCoordinates->z_end }
.ToTileStart();
int32_t direction = (vehicle->track_direction + trackCoordinates->rotation_end) & 3;
auto tileElement = map_get_wall_element_at(x, y, z, direction);
auto tileElement = map_get_wall_element_at(CoordsXYZD{ wallCoords, static_cast<Direction>(direction) });
if (tileElement == nullptr)
{
return;
@ -7444,7 +7443,7 @@ static void vehicle_update_scenery_door(rct_vehicle* vehicle)
{
tileElement->SetAnimationIsBackwards(false);
tileElement->SetAnimationFrame(1);
map_animation_create(MAP_ANIMATION_TYPE_WALL_DOOR, x, y, z);
map_animation_create(MAP_ANIMATION_TYPE_WALL_DOOR, wallCoords.x, wallCoords.y, wallCoords.z >> 3);
vehicle_play_scenery_door_open_sound(vehicle, tileElement);
}
@ -7509,13 +7508,12 @@ static void vehicle_update_handle_scenery_door(rct_vehicle* vehicle)
int32_t trackType = vehicle->track_type >> 2;
const rct_preview_track* trackBlock = TrackBlocks[trackType];
const rct_track_coordinates* trackCoordinates = &TrackCoordinates[trackType];
int32_t x = vehicle->track_x;
int32_t y = vehicle->track_y;
int32_t z = (vehicle->track_z - trackBlock->z + trackCoordinates->z_begin) >> 3;
auto wallCoords = CoordsXYZ{ vehicle->track_x, vehicle->track_y,
vehicle->track_z - trackBlock->z + trackCoordinates->z_begin };
int32_t direction = (vehicle->track_direction + trackCoordinates->rotation_begin) & 3;
direction = direction_reverse(direction);
auto tileElement = map_get_wall_element_at(x, y, z, direction);
auto tileElement = map_get_wall_element_at(CoordsXYZD{ wallCoords, static_cast<Direction>(direction) });
if (tileElement == nullptr)
{
return;
@ -7525,7 +7523,7 @@ static void vehicle_update_handle_scenery_door(rct_vehicle* vehicle)
{
tileElement->SetAnimationIsBackwards(true);
tileElement->SetAnimationFrame(1);
map_animation_create(MAP_ANIMATION_TYPE_WALL_DOOR, x, y, z);
map_animation_create(MAP_ANIMATION_TYPE_WALL_DOOR, wallCoords.x, wallCoords.y, wallCoords.z >> 3);
vehicle_play_scenery_door_open_sound(vehicle, tileElement);
}

View File

@ -238,6 +238,11 @@ struct CoordsXYZ : public CoordsXY
{
return x == other.x && y == other.y && z == other.z;
}
CoordsXYZ ToTileStart() const
{
return { floor2(x, 32), floor2(y, 32), z };
}
};
struct TileCoordsXYZ

View File

@ -2338,18 +2338,19 @@ TileElement* map_get_track_element_at_with_direction_from_ride(
return nullptr;
};
WallElement* map_get_wall_element_at(int32_t x, int32_t y, int32_t z, int32_t direction)
WallElement* map_get_wall_element_at(CoordsXYZD wallCoords)
{
TileElement* tileElement = map_get_first_element_at(x >> 5, y >> 5);
auto tileWallCoords = TileCoordsXYZ(wallCoords);
TileElement* tileElement = map_get_first_element_at(tileWallCoords.x, tileWallCoords.y);
if (tileElement == nullptr)
return nullptr;
do
{
if (tileElement->GetType() != TILE_ELEMENT_TYPE_WALL)
continue;
if (tileElement->base_height != z)
if (tileElement->base_height != tileWallCoords.z)
continue;
if (tileElement->GetDirection() != direction)
if (tileElement->GetDirection() != wallCoords.direction)
continue;
return tileElement->AsWall();

View File

@ -146,7 +146,7 @@ BannerElement* map_get_banner_element_at(int32_t x, int32_t y, int32_t z, uint8_
SurfaceElement* map_get_surface_element_at(int32_t x, int32_t y);
SurfaceElement* map_get_surface_element_at(const CoordsXY& coords);
PathElement* map_get_path_element_at(const TileCoordsXYZ& loc);
WallElement* map_get_wall_element_at(int32_t x, int32_t y, int32_t z, int32_t direction);
WallElement* map_get_wall_element_at(CoordsXYZD wallCoords);
SmallSceneryElement* map_get_small_scenery_element_at(int32_t x, int32_t y, int32_t z, int32_t type, uint8_t quadrant);
EntranceElement* map_get_park_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost);
EntranceElement* map_get_ride_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost);