Replace more direct accesses to base/clearance Z with getter/setter (#10454)

This commit is contained in:
Michael Steenbeek 2019-12-27 15:26:40 +01:00 committed by GitHub
parent 26cce7e82b
commit 8ca0cf52a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 85 additions and 64 deletions

View File

@ -296,7 +296,8 @@ int32_t viewport_interaction_get_item_right(ScreenCoordsXY screenCoords, viewpor
}
else
{
if (!gCheatsSandboxMode && !map_is_location_owned({ info->x, info->y, tileElement->base_height << 4 }))
// FIXME: Why does it *2 the value?
if (!gCheatsSandboxMode && !map_is_location_owned({ info->x, info->y, tileElement->GetBaseZ() * 2 }))
{
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
}

View File

@ -731,7 +731,7 @@ static void window_footpath_set_provisional_path_at_point(ScreenCoordsXY screenC
{
// Check for change
if ((gFootpathProvisionalFlags & PROVISIONAL_PATH_FLAG_1) && gFootpathProvisionalPosition.x == mapCoord.x
&& gFootpathProvisionalPosition.y == mapCoord.y && gFootpathProvisionalPosition.z / 8 == tileElement->base_height)
&& gFootpathProvisionalPosition.y == mapCoord.y && gFootpathProvisionalPosition.z == tileElement->GetBaseZ())
{
return;
}
@ -771,15 +771,15 @@ static void window_footpath_set_provisional_path_at_point(ScreenCoordsXY screenC
break;
}
}
uint8_t z = tileElement->base_height;
uint8_t z = tileElement->GetBaseZ();
if (slope & RAISE_FOOTPATH_FLAG)
{
slope &= ~RAISE_FOOTPATH_FLAG;
z += 2;
z += (2 * 8);
}
int32_t pathType = (gFootpathSelectedType << 7) + (gFootpathSelectedId & 0xFF);
_window_footpath_cost = footpath_provisional_set(pathType, { mapCoord, z * 8 }, slope);
_window_footpath_cost = footpath_provisional_set(pathType, { mapCoord, z }, slope);
window_invalidate_by_class(WC_FOOTPATH);
}
}
@ -815,20 +815,20 @@ static void window_footpath_set_selection_start_bridge_at_point(ScreenCoordsXY s
gMapSelectArrowPosition.x = x;
gMapSelectArrowPosition.y = y;
int32_t z = tileElement->base_height;
int32_t z = tileElement->GetBaseZ();
if (tileElement->GetType() == TILE_ELEMENT_TYPE_SURFACE)
{
uint8_t slope = tileElement->AsSurface()->GetSlope();
if (slope & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
{
z += 2;
z += (2 * 8);
} // Add 2 for a slope
if (slope & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
z += 2; // Add another 2 for a steep slope
z += (2 * 8); // Add another 2 for a steep slope
}
gMapSelectArrowPosition.z = z << 3;
gMapSelectArrowPosition.z = z;
map_invalidate_selection_rect();
}
@ -874,17 +874,17 @@ static void window_footpath_place_path_at_point(ScreenCoordsXY screenCoords)
}
break;
}
z = tileElement->base_height;
z = tileElement->GetBaseZ();
if (currentType & RAISE_FOOTPATH_FLAG)
{
currentType &= ~RAISE_FOOTPATH_FLAG;
z += 2;
z += (2 * 8);
}
selectedType = (gFootpathSelectedType << 7) + (gFootpathSelectedId & 0xFF);
// Try and place path
gGameCommandErrorTitle = STR_CANT_BUILD_FOOTPATH_HERE;
auto footpathPlaceAction = FootpathPlaceAction({ mapCoord.x, mapCoord.y, z * 8 }, currentType, selectedType);
auto footpathPlaceAction = FootpathPlaceAction({ mapCoord.x, mapCoord.y, z }, currentType, selectedType);
footpathPlaceAction.SetCallback([](const GameAction* ga, const GameActionResult* result) {
if (result->Error == GA_ERROR::OK)
{
@ -922,28 +922,28 @@ static void window_footpath_start_bridge_at_point(ScreenCoordsXY screenCoords)
// If we start the path on a slope, the arrow is slightly raised, so we
// expect the path to be slightly raised as well.
uint8_t slope = tileElement->AsSurface()->GetSlope();
z = tileElement->base_height;
z = tileElement->GetBaseZ();
if (slope & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
{
// Steep diagonal slope
z += 4;
z += (4 * 8);
}
else if (slope & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
{
// Normal slope
z += 2;
z += (2 * 8);
}
}
else
{
z = tileElement->base_height;
z = tileElement->GetBaseZ();
if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH)
{
if (tileElement->AsPath()->IsSloped())
{
if (direction == (tileElement->AsPath()->GetSlopeDirection()))
{
z += 2;
z += (2 * 8);
}
}
}
@ -952,7 +952,7 @@ static void window_footpath_start_bridge_at_point(ScreenCoordsXY screenCoords)
tool_cancel();
gFootpathConstructFromPosition.x = x;
gFootpathConstructFromPosition.y = y;
gFootpathConstructFromPosition.z = z * 8;
gFootpathConstructFromPosition.z = z;
gFootpathConstructDirection = direction;
gFootpathProvisionalFlags = 0;
_window_footpath_provisional_path_arrow_timer = 0;
@ -1016,14 +1016,14 @@ static void window_footpath_construct()
*/
static void footpath_remove_tile_element(TileElement* tileElement)
{
auto z = tileElement->base_height;
auto z = tileElement->GetBaseZ();
if (tileElement->AsPath()->IsSloped())
{
uint8_t slopeDirection = tileElement->AsPath()->GetSlopeDirection();
slopeDirection = direction_reverse(slopeDirection);
if (slopeDirection == gFootpathConstructDirection)
{
z += 2;
z += (2 * 8);
}
}
@ -1054,7 +1054,7 @@ static void footpath_remove_tile_element(TileElement* tileElement)
edge = direction_reverse(edge);
gFootpathConstructFromPosition.x -= CoordsDirectionDelta[edge].x;
gFootpathConstructFromPosition.y -= CoordsDirectionDelta[edge].y;
gFootpathConstructFromPosition.z = z * 8;
gFootpathConstructFromPosition.z = z;
gFootpathConstructDirection = edge;
gFootpathConstructValidDirections = 255;
}

View File

@ -2459,8 +2459,8 @@ static void sub_6CBCE2(
_tempTrackTileElement.AsTrack()->SetHasChain((liftHillAndInvertedState & CONSTRUCTION_LIFT_HILL_SELECTED) != 0);
_tempTrackTileElement.SetOccupiedQuadrants(quarterTile.GetBaseQuarterOccupied());
_tempTrackTileElement.SetLastForTile(true);
_tempTrackTileElement.base_height = baseZ / 8;
_tempTrackTileElement.clearance_height = clearanceZ / 8;
_tempTrackTileElement.SetBaseZ(baseZ);
_tempTrackTileElement.SetClearanceZ(clearanceZ);
_tempTrackTileElement.AsTrack()->SetTrackType(trackType);
_tempTrackTileElement.AsTrack()->SetSequenceIndex(trackBlock->index);
_tempTrackTileElement.AsTrack()->SetHasCableLift(false);

View File

@ -184,7 +184,7 @@ private:
auto pathElement = tileElement->AsPath();
if (pathElement->base_height != _loc.z / 8 && pathElement->base_height != _loc.z / 8 - 2)
if (pathElement->GetBaseZ() != _loc.z && pathElement->GetBaseZ() != _loc.z - (2 * 8))
continue;
if (!(pathElement->GetEdges() & (1 << _loc.direction)))

View File

@ -138,7 +138,7 @@ private:
break;
if (tileElement->GetType() != TILE_ELEMENT_TYPE_BANNER)
continue;
if (tileElement->base_height != _loc.z / 8)
if (tileElement->GetBaseZ() != _loc.z)
continue;
if (tileElement->IsGhost() && !(GetFlags() & GAME_COMMAND_FLAG_GHOST))
continue;

View File

@ -178,7 +178,7 @@ public:
if (sceneryElement->AsLargeScenery()->GetSequenceIndex() != i)
continue;
if (sceneryElement->base_height != currentTile.z / 8)
if (sceneryElement->GetBaseZ() != currentTile.z)
continue;
// If we are removing ghost elements
@ -216,7 +216,7 @@ private:
if (tileElement->GetType() != TILE_ELEMENT_TYPE_LARGE_SCENERY)
continue;
if (tileElement->base_height != _loc.z / 8)
if (tileElement->GetBaseZ() != _loc.z)
continue;
if (tileElement->AsLargeScenery()->GetSequenceIndex() != _tileIndex)

View File

@ -744,8 +744,8 @@ private:
if (surfaceElement->GetOwnership() & OWNERSHIP_OWNED)
continue;
int32_t base_z = surfaceElement->base_height;
int32_t destOwnership = check_max_allowable_land_rights_for_tile({ coords, base_z << 3 });
int32_t base_z = surfaceElement->GetBaseZ();
int32_t destOwnership = check_max_allowable_land_rights_for_tile({ coords, base_z });
// only own tiles that were not set to 0
if (destOwnership != OWNERSHIP_UNOWNED)

View File

@ -441,7 +441,7 @@ public:
sceneryElement->SetAge(0);
sceneryElement->SetPrimaryColour(_primaryColour);
sceneryElement->SetSecondaryColour(_secondaryColour);
sceneryElement->clearance_height = sceneryElement->base_height + ((sceneryEntry->small_scenery.height + 7) / 8);
sceneryElement->SetClearanceZ(sceneryElement->GetBaseZ() + sceneryEntry->small_scenery.height + 7);
if (supportsRequired)
{

View File

@ -145,7 +145,7 @@ private:
continue;
if ((tileElement->AsSmallScenery()->GetSceneryQuadrant()) != _quadrant)
continue;
if (tileElement->base_height != _loc.z / 8)
if (tileElement->GetBaseZ() != _loc.z)
continue;
if (tileElement->AsSmallScenery()->GetEntryIndex() != _sceneryType)
continue;

View File

@ -163,7 +163,7 @@ public:
if (tileElement == nullptr)
break;
if (tileElement->base_height != mapLoc.z / 8)
if (tileElement->GetBaseZ() != mapLoc.z)
continue;
if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK)
@ -353,7 +353,7 @@ public:
if (tileElement == nullptr)
break;
if (tileElement->base_height != mapLoc.z / 8)
if (tileElement->GetBaseZ() != mapLoc.z)
continue;
if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK)

View File

@ -176,7 +176,7 @@ public:
}
}
if (targetHeight / 8 < surfaceElement->base_height && !gCheatsDisableClearanceChecks)
if (targetHeight < surfaceElement->GetBaseZ() && !gCheatsDisableClearanceChecks)
{
return std::make_unique<WallPlaceActionResult>(GA_ERROR::DISALLOWED, STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND);
}

View File

@ -104,7 +104,7 @@ private:
{
if (tileElement->GetType() != TILE_ELEMENT_TYPE_WALL)
continue;
if (tileElement->base_height != location.z / 8)
if (tileElement->GetBaseZ() != location.z)
continue;
if (tileElement->GetDirection() != location.direction)
continue;

View File

@ -317,14 +317,14 @@ void lightfx_prepare_light_list()
}
int32_t minDist = 0;
int32_t baseHeight = -999;
int32_t baseHeight = (-999) * 8;
if (interactionType != VIEWPORT_INTERACTION_ITEM_SPRITE && tileElement)
{
baseHeight = tileElement->base_height;
baseHeight = tileElement->GetBaseZ();
}
minDist = ((baseHeight * 8) - coord_3d.z) / 2;
minDist = (baseHeight - coord_3d.z) / 2;
int32_t deltaX = mapCoord.x - coord_3d.x;
int32_t deltaY = mapCoord.y - coord_3d.y;

View File

@ -860,12 +860,11 @@ void path_paint(paint_session* session, uint16_t height, const TileElement* tile
auto surface = map_get_surface_element_at(CoordsXY{ session->MapPosition.x, session->MapPosition.y });
uint16_t bl = height / 8;
if (surface == nullptr)
{
hasSupports = true;
}
else if (surface->base_height != bl)
else if (surface->GetBaseZ() != height)
{
hasSupports = true;
}

View File

@ -960,10 +960,10 @@ void surface_paint(paint_session* session, uint8_t direction, uint16_t height, c
const uint32_t surfaceSlope = viewport_surface_paint_setup_get_relative_slope(
reinterpret_cast<TileElement*>(surfaceElement), rotation);
const uint8_t baseHeight = surfaceElement->base_height / 2;
const uint8_t baseHeight = surfaceElement->GetBaseZ() / 16;
const corner_height& ch = corner_heights[surfaceSlope];
descriptor.tile_coords = { position.x / 32, position.y / 32 };
descriptor.tile_coords = TileCoordsXY{ position };
descriptor.tile_element = reinterpret_cast<TileElement*>(surfaceElement);
descriptor.terrain = surfaceElement->GetSurfaceStyle();
descriptor.slope = surfaceSlope;

View File

@ -263,7 +263,7 @@ static void sub_68B3FB(paint_session* session, int32_t x, int32_t y)
TileElement* tile_element_sub_iterator = tile_element;
while (!(tile_element_sub_iterator++)->IsLastForTile())
{
if (tile_element_sub_iterator->base_height != tile_element->base_height)
if (tile_element_sub_iterator->GetBaseZ() != tile_element->GetBaseZ())
{
break;
}

View File

@ -4181,7 +4181,7 @@ void Guest::UpdateRideLeaveVehicle()
{
if (inner_map->GetType() != TILE_ELEMENT_TYPE_TRACK)
continue;
if (inner_map->base_height == vehicle->track_z / 8)
if (inner_map->GetBaseZ() == vehicle->track_z)
break;
}
@ -6893,7 +6893,7 @@ void Guest::UpdateSpriteType()
{
if (tileElement == nullptr)
break;
if ((z / 8) < tileElement->base_height)
if (z < tileElement->GetBaseZ())
break;
if (tileElement->IsLastForTile())

View File

@ -2040,8 +2040,8 @@ private:
dst->ClearAs(tileElementType);
dst->SetDirection(src->GetDirection());
dst->flags = src->flags;
dst->base_height = src->base_height / 2;
dst->clearance_height = src->clearance_height / 2;
dst->SetBaseZ(src->base_height * 4);
dst->SetClearanceZ(src->clearance_height * 4);
switch (tileElementType)
{

View File

@ -6961,7 +6961,6 @@ void sub_6CB945(Ride* ride)
while ((++trackBlock)->index != 0xFF)
{
CoordsXYZ blockLocation = location + CoordsXYZ{ CoordsXY{ trackBlock->x, trackBlock->y }.Rotate(direction), 0 };
auto blockTileHeight = TileCoordsXYZ(blockLocation).z;
bool trackFound = false;
tileElement = map_get_first_element_at(blockLocation);
@ -6969,7 +6968,7 @@ void sub_6CB945(Ride* ride)
break;
do
{
if (blockTileHeight != tileElement->base_height)
if (blockLocation.z != tileElement->GetBaseZ())
continue;
if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK)
continue;

View File

@ -133,7 +133,7 @@ void maze_entrance_hedge_replacement(int32_t x, int32_t y, TileElement* tileElem
int32_t direction = tileElement->GetDirection();
x += CoordsDirectionDelta[direction].x;
y += CoordsDirectionDelta[direction].y;
int32_t z = tileElement->base_height;
int32_t z = tileElement->GetBaseZ();
ride_id_t rideIndex = tileElement->AsEntrance()->GetRideIndex();
tileElement = map_get_first_element_at({ x, y });
@ -145,7 +145,7 @@ void maze_entrance_hedge_replacement(int32_t x, int32_t y, TileElement* tileElem
continue;
if (tileElement->AsTrack()->GetRideIndex() != rideIndex)
continue;
if (tileElement->base_height != z)
if (tileElement->GetBaseZ() != z)
continue;
if (tileElement->AsTrack()->GetTrackType() != TRACK_ELEM_MAZE)
continue;
@ -171,7 +171,7 @@ void maze_entrance_hedge_removal(int32_t x, int32_t y, TileElement* tileElement)
int32_t direction = tileElement->GetDirection();
x += CoordsDirectionDelta[direction].x;
y += CoordsDirectionDelta[direction].y;
int32_t z = tileElement->base_height;
int32_t z = tileElement->GetBaseZ();
ride_id_t rideIndex = tileElement->AsEntrance()->GetRideIndex();
tileElement = map_get_first_element_at({ x, y });
@ -183,7 +183,7 @@ void maze_entrance_hedge_removal(int32_t x, int32_t y, TileElement* tileElement)
continue;
if (tileElement->AsTrack()->GetRideIndex() != rideIndex)
continue;
if (tileElement->base_height != z)
if (tileElement->GetBaseZ() != z)
continue;
if (tileElement->AsTrack()->GetTrackType() != TRACK_ELEM_MAZE)
continue;

View File

@ -243,7 +243,7 @@ bool JumpingFountain::IsJumpingFountain(const int32_t newType, const CoordsXYZ n
{
if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH)
continue;
if (tileElement->base_height != newLoc.z / 8)
if (tileElement->GetBaseZ() != newLoc.z)
continue;
if (tileElement->AsPath()->AdditionIsGhost())
continue;

View File

@ -706,7 +706,7 @@ bool map_is_location_owned(const CoordsXYZ& loc)
if (surfaceElement->GetOwnership() & OWNERSHIP_CONSTRUCTION_RIGHTS_OWNED)
{
if (loc.z / 8 < surfaceElement->base_height || loc.z / 8 - 2 > surfaceElement->base_height)
if (loc.z < surfaceElement->GetBaseZ() || loc.z - (2 * 8) > surfaceElement->GetBaseZ())
return true;
}
}
@ -2212,7 +2212,7 @@ TrackElement* map_get_track_element_at_of_type(CoordsXYZD location, int32_t trac
auto trackElement = tileElement->AsTrack();
if (trackElement != nullptr)
{
if (trackElement->base_height != location.z / 8)
if (trackElement->GetBaseZ() != location.z)
continue;
if (trackElement->GetDirection() != location.direction)
continue;
@ -2235,7 +2235,7 @@ TrackElement* map_get_track_element_at_of_type_seq(CoordsXYZD location, int32_t
auto trackElement = tileElement->AsTrack();
if (trackElement != nullptr)
{
if (trackElement->base_height != location.z / 8)
if (trackElement->GetBaseZ() != location.z)
continue;
if (trackElement->GetDirection() != location.direction)
continue;

View File

@ -121,10 +121,10 @@ void SurfaceElement::UpdateGrassLength(CoordsXY coords)
// Grass can't grow any further than CLUMPS_2 but this code also cuts grass
// if there is an object placed on top of it.
int32_t z0 = base_height;
int32_t z1 = base_height + 2;
int32_t zLow = GetBaseZ();
int32_t zHigh = GetBaseZ() + (2 * 8);
if (Slope & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
z1 += 2;
zHigh += (2 * 8);
// Check objects above grass
TileElement* tileElementAbove = (TileElement*)this;
@ -166,9 +166,9 @@ void SurfaceElement::UpdateGrassLength(CoordsXY coords)
// Grass should not be affected by ghost elements.
if (tileElementAbove->IsGhost())
continue;
if (z0 >= tileElementAbove->clearance_height)
if (zLow >= tileElementAbove->GetClearanceZ())
continue;
if (z1 < tileElementAbove->base_height)
if (zHigh < tileElementAbove->GetBaseZ())
continue;
if (grassLengthTmp != GRASS_LENGTH_CLEAR_0)

View File

@ -230,7 +230,17 @@ int32_t TileElementBase::GetBaseZ() const
return base_height * 8;
}
void TileElementBase::SetBaseZ(int32_t newZ)
{
base_height = (newZ / 8);
}
int32_t TileElementBase::GetClearanceZ() const
{
return clearance_height * 8;
}
void TileElementBase::SetClearanceZ(int32_t newZ)
{
clearance_height = (newZ / 8);
}

View File

@ -79,7 +79,9 @@ struct TileElementBase
uint8_t GetOccupiedQuadrants() const;
void SetOccupiedQuadrants(uint8_t quadrants);
int32_t GetBaseZ() const;
void SetBaseZ(int32_t newZ);
int32_t GetClearanceZ() const;
void SetClearanceZ(int32_t newZ);
};
/**

View File

@ -794,7 +794,7 @@ GameActionResult::Ptr tile_inspector_track_base_height_offset(
if (tileElement == nullptr)
break;
if (tileElement->base_height != elemZ / 8)
if (tileElement->GetBaseZ() != elemZ)
continue;
if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK)
@ -901,7 +901,7 @@ GameActionResult::Ptr tile_inspector_track_set_chain(
if (tileElement == nullptr)
break;
if (tileElement->base_height != elemZ / 8)
if (tileElement->GetBaseZ() != elemZ)
continue;
if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK)

View File

@ -469,7 +469,17 @@ int32_t TileElementBase::GetBaseZ() const
return base_height * 8;
}
void TileElementBase::SetBaseZ(int32_t newZ)
{
base_height = (newZ / 8);
}
int32_t TileElementBase::GetClearanceZ() const
{
return clearance_height * 8;
}
void TileElementBase::SetClearanceZ(int32_t newZ)
{
clearance_height = (newZ / 8);
}