mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +01:00
Use safe method to access ted block
This commit is contained in:
@@ -137,8 +137,13 @@ GameActions::Result TrackRemoveAction::Query() const
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_NONE);
|
||||
}
|
||||
const auto& ted = GetTrackElementDescriptor(trackType);
|
||||
const rct_preview_track* trackBlock = ted.Block;
|
||||
trackBlock += tileElement->AsTrack()->GetSequenceIndex();
|
||||
auto sequenceIndex = tileElement->AsTrack()->GetSequenceIndex();
|
||||
const rct_preview_track* trackBlock = ted.GetBlockForSequence(sequenceIndex);
|
||||
if (trackBlock == nullptr)
|
||||
{
|
||||
log_warning("Track block %d not found for track type %d.", sequenceIndex, trackType);
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_NONE);
|
||||
}
|
||||
|
||||
auto startLoc = _origin;
|
||||
startLoc.direction = tileElement->GetDirection();
|
||||
@@ -321,8 +326,13 @@ GameActions::Result TrackRemoveAction::Execute() const
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_NONE);
|
||||
}
|
||||
const auto& ted = GetTrackElementDescriptor(trackType);
|
||||
const rct_preview_track* trackBlock = ted.Block;
|
||||
trackBlock += tileElement->AsTrack()->GetSequenceIndex();
|
||||
auto sequenceIndex = tileElement->AsTrack()->GetSequenceIndex();
|
||||
const rct_preview_track* trackBlock = ted.GetBlockForSequence(sequenceIndex);
|
||||
if (trackBlock == nullptr)
|
||||
{
|
||||
log_warning("Track block %d not found for track type %d.", sequenceIndex, trackType);
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_NONE);
|
||||
}
|
||||
|
||||
auto startLoc = _origin;
|
||||
startLoc.direction = tileElement->GetDirection();
|
||||
|
||||
@@ -447,7 +447,7 @@ bool WallPlaceAction::WallCheckObstructionWithTrack(
|
||||
direction = DirectionReverse(trackElement->GetDirection());
|
||||
if (direction == _edge)
|
||||
{
|
||||
const rct_preview_track* trackBlock = &ted.Block[sequence];
|
||||
const rct_preview_track* trackBlock = ted.GetBlockForSequence(sequence);
|
||||
z = ted.Coordinates.z_begin;
|
||||
z = trackElement->base_height + ((z - trackBlock->z) * 8);
|
||||
if (z == z0)
|
||||
@@ -459,7 +459,7 @@ bool WallPlaceAction::WallCheckObstructionWithTrack(
|
||||
}
|
||||
}
|
||||
|
||||
const rct_preview_track* trackBlock = &ted.Block[sequence + 1];
|
||||
const rct_preview_track* trackBlock = ted.GetBlockForSequence(sequence + 1);
|
||||
if (trackBlock->index != 0xFF)
|
||||
{
|
||||
return false;
|
||||
@@ -482,7 +482,7 @@ bool WallPlaceAction::WallCheckObstructionWithTrack(
|
||||
return false;
|
||||
}
|
||||
|
||||
trackBlock = &ted.Block[sequence];
|
||||
trackBlock = ted.GetBlockForSequence(sequence);
|
||||
z = ted.Coordinates.z_end;
|
||||
z = trackElement->base_height + ((z - trackBlock->z) * 8);
|
||||
return z == z0;
|
||||
|
||||
@@ -625,12 +625,11 @@ bool track_block_get_previous_from_zero(
|
||||
continue;
|
||||
|
||||
const auto* ted = &GetTrackElementDescriptor(trackElement->GetTrackType());
|
||||
const auto* nextTrackBlock = ted->Block;
|
||||
if (nextTrackBlock == nullptr)
|
||||
continue;
|
||||
const auto& nextTrackCoordinate = ted->Coordinates;
|
||||
|
||||
nextTrackBlock += trackElement->GetSequenceIndex();
|
||||
const auto* nextTrackBlock = ted->GetBlockForSequence(trackElement->GetSequenceIndex());
|
||||
if (nextTrackBlock == nullptr)
|
||||
continue;
|
||||
if ((nextTrackBlock + 1)->index != 255)
|
||||
continue;
|
||||
|
||||
@@ -703,12 +702,10 @@ bool track_block_get_previous(const CoordsXYE& trackPos, track_begin_end* outTra
|
||||
if (ride == nullptr)
|
||||
return false;
|
||||
|
||||
const auto* trackBlock = ted.Block;
|
||||
const auto* trackBlock = ted.GetBlockForSequence(trackElement->GetSequenceIndex());
|
||||
if (trackBlock == nullptr)
|
||||
return false;
|
||||
|
||||
trackBlock += trackElement->GetSequenceIndex();
|
||||
|
||||
auto trackCoordinate = ted.Coordinates;
|
||||
|
||||
int32_t z = trackElement->GetBaseZ();
|
||||
|
||||
@@ -391,33 +391,36 @@ std::optional<CoordsXYZ> GetTrackElementOriginAndApplyChanges(
|
||||
|
||||
// Possibly z should be & 0xF8
|
||||
const auto& ted = GetTrackElementDescriptor(type);
|
||||
const auto* trackBlock = ted.Block;
|
||||
if (trackBlock == nullptr)
|
||||
return std::nullopt;
|
||||
|
||||
// Now find all the elements that belong to this track piece
|
||||
int32_t sequence = trackElement->GetSequenceIndex();
|
||||
uint8_t mapDirection = trackElement->GetDirection();
|
||||
const auto* trackBlock = ted.GetBlockForSequence(sequence);
|
||||
if (trackBlock == nullptr)
|
||||
return std::nullopt;
|
||||
|
||||
CoordsXY offsets = { trackBlock[sequence].x, trackBlock[sequence].y };
|
||||
CoordsXY offsets = { trackBlock->x, trackBlock->y };
|
||||
CoordsXY newCoords = location;
|
||||
newCoords += offsets.Rotate(DirectionReverse(mapDirection));
|
||||
|
||||
auto retCoordsXYZ = CoordsXYZ{ newCoords.x, newCoords.y, location.z - trackBlock[sequence].z };
|
||||
auto retCoordsXYZ = CoordsXYZ{ newCoords.x, newCoords.y, location.z - trackBlock->z };
|
||||
|
||||
int32_t start_z = retCoordsXYZ.z;
|
||||
retCoordsXYZ.z += trackBlock[0].z;
|
||||
for (int32_t i = 0; trackBlock[i].index != 0xFF; ++i)
|
||||
const auto block0 = ted.GetBlockForSequence(0);
|
||||
assert(block0 != nullptr);
|
||||
|
||||
retCoordsXYZ.z += block0->z;
|
||||
for (int32_t i = 0; ted.Block[i].index != 0xFF; ++i)
|
||||
{
|
||||
CoordsXY cur = { retCoordsXYZ };
|
||||
offsets = { trackBlock[i].x, trackBlock[i].y };
|
||||
offsets = { ted.Block[i].x, ted.Block[i].y };
|
||||
cur += offsets.Rotate(mapDirection);
|
||||
int32_t cur_z = start_z + trackBlock[i].z;
|
||||
int32_t cur_z = start_z + ted.Block[i].z;
|
||||
|
||||
MapInvalidateTileFull(cur);
|
||||
|
||||
trackElement = MapGetTrackElementAtOfTypeSeq(
|
||||
{ cur, cur_z, static_cast<Direction>(location.direction) }, type, trackBlock[i].index);
|
||||
{ cur, cur_z, static_cast<Direction>(location.direction) }, type, ted.Block[i].index);
|
||||
if (trackElement == nullptr)
|
||||
{
|
||||
return std::nullopt;
|
||||
|
||||
@@ -669,7 +669,10 @@ std::optional<CoordsXYZD> GetTrackSegmentOrigin(const CoordsXYE& posEl)
|
||||
auto coords = CoordsXYZ(posEl.x, posEl.y, trackEl->GetBaseZ());
|
||||
|
||||
// Subtract the current sequence's offset
|
||||
const auto* trackBlock = &ted.Block[trackEl->GetSequenceIndex()];
|
||||
const auto* trackBlock = ted.GetBlockForSequence(trackEl->GetSequenceIndex());
|
||||
if (trackBlock == nullptr)
|
||||
return {};
|
||||
|
||||
CoordsXY trackBlockOffset = { trackBlock->x, trackBlock->y };
|
||||
coords += trackBlockOffset.Rotate(DirectionReverse(direction));
|
||||
coords.z -= trackBlock->z;
|
||||
|
||||
@@ -780,8 +780,9 @@ namespace OpenRCT2::TileInspector
|
||||
return GameActions::Result(GameActions::Status::Unknown, STR_NONE, STR_NONE);
|
||||
|
||||
const auto& ted = GetTrackElementDescriptor(type);
|
||||
const auto* trackBlock = ted.Block;
|
||||
trackBlock += trackElement->AsTrack()->GetSequenceIndex();
|
||||
const auto* trackBlock = ted.GetBlockForSequence(trackElement->AsTrack()->GetSequenceIndex());
|
||||
if (trackBlock == nullptr)
|
||||
return GameActions::Result(GameActions::Status::Unknown, STR_NONE, STR_NONE);
|
||||
|
||||
uint8_t originDirection = trackElement->GetDirection();
|
||||
CoordsXY offsets = { trackBlock->x, trackBlock->y };
|
||||
@@ -863,8 +864,9 @@ namespace OpenRCT2::TileInspector
|
||||
return GameActions::Result(GameActions::Status::Unknown, STR_NONE, STR_NONE);
|
||||
|
||||
const auto& ted = GetTrackElementDescriptor(type);
|
||||
auto trackBlock = ted.Block;
|
||||
trackBlock += trackElement->AsTrack()->GetSequenceIndex();
|
||||
auto trackBlock = ted.GetBlockForSequence(trackElement->AsTrack()->GetSequenceIndex());
|
||||
if (trackBlock == nullptr)
|
||||
return GameActions::Result(GameActions::Status::Unknown, STR_NONE, STR_NONE);
|
||||
|
||||
uint8_t originDirection = trackElement->GetDirection();
|
||||
CoordsXY offsets = { trackBlock->x, trackBlock->y };
|
||||
|
||||
Reference in New Issue
Block a user