diff --git a/src/openrct2/core/Compression.cpp b/src/openrct2/core/Compression.cpp index ec89398eac..8e585c36d2 100644 --- a/src/openrct2/core/Compression.cpp +++ b/src/openrct2/core/Compression.cpp @@ -41,12 +41,11 @@ namespace OpenRCT2::Compression if (sourceLength > source.GetLength() - source.GetPosition()) throw IOException("Not Enough Data to Compress"); - int ret; StreamReadBuffer sourceBuf(source, sourceLength, kZlibChunkSize); StreamWriteBuffer destBuf(dest, zlibCompressBound(sourceLength), kZlibChunkSize); z_stream strm{}; - ret = deflateInit2(&strm, level, Z_DEFLATED, kZlibWindowBits[static_cast(header)], 8, Z_DEFAULT_STRATEGY); + int ret = deflateInit2(&strm, level, Z_DEFLATED, kZlibWindowBits[static_cast(header)], 8, Z_DEFAULT_STRATEGY); if (ret != Z_OK) { LOG_ERROR("Failed to initialise stream"); @@ -88,12 +87,11 @@ namespace OpenRCT2::Compression if (sourceLength > source.GetLength() - source.GetPosition()) throw IOException("Not Enough Data to Decompress"); - int ret; StreamReadBuffer sourceBuf(source, sourceLength, kZlibChunkSize); StreamWriteBuffer destBuf(dest, decompressLength, kZlibChunkSize); z_stream strm{}; - ret = inflateInit2(&strm, kZlibWindowBits[static_cast(header)]); + int ret = inflateInit2(&strm, kZlibWindowBits[static_cast(header)]); if (ret != Z_OK) { LOG_ERROR("Failed to initialise stream"); @@ -157,7 +155,6 @@ namespace OpenRCT2::Compression if (sourceLength > source.GetLength() - source.GetPosition()) throw IOException("Not Enough Data to Compress"); - size_t ret; StreamReadBuffer sourceBuf(source, sourceLength, ZSTD_CStreamInSize()); StreamWriteBuffer destBuf(dest, zstdCompressBound(sourceLength), ZSTD_CStreamOutSize()); unsigned metaFlags = static_cast(metadata); @@ -170,7 +167,7 @@ namespace OpenRCT2::Compression return false; } - ret = ZSTD_CCtx_setParameter(ctx.get(), ZSTD_c_compressionLevel, level); + size_t ret = ZSTD_CCtx_setParameter(ctx.get(), ZSTD_c_compressionLevel, level); if (ZSTD_isError(ret)) { LOG_ERROR("Failed to set compression level with error: %s", ZSTD_getErrorName(ret)); diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index 99b267af9a..e0a488fd81 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -4355,10 +4355,9 @@ void Guest::UpdateRideLeaveVehicle() return; } - CoordsXYZ waypointLoc; const auto& rtd = ride->getRideTypeDescriptor(); - waypointLoc = { rtd.GetGuestWaypointLocation(*vehicle, *ride, CurrentRideStation), - exitLocation.z + ride->getRideTypeDescriptor().Heights.PlatformHeight }; + CoordsXYZ waypointLoc = { rtd.GetGuestWaypointLocation(*vehicle, *ride, CurrentRideStation), + exitLocation.z + ride->getRideTypeDescriptor().Heights.PlatformHeight }; rideEntry = vehicle->GetRideEntry(); carEntry = &rideEntry->Cars[vehicle->vehicle_type]; @@ -4559,10 +4558,9 @@ void Guest::UpdateRideApproachVehicleWaypoints() void UpdateRideApproachVehicleWaypointsMotionSimulator(Guest& guest, const CoordsXY& loc, int16_t& xy_distance) { - int16_t actionZ; auto ride = GetRide(guest.CurrentRide); - // Motion simulators have steps this moves the peeps up the steps - actionZ = ride->getStation(guest.CurrentRideStation).GetBaseZ() + 2; + // Motion simulators have steps. This moves the peeps up the steps. + int16_t actionZ = ride->getStation(guest.CurrentRideStation).GetBaseZ() + 2; uint8_t waypoint = guest.Var37 & 3; if (waypoint == 2) @@ -6487,11 +6485,8 @@ bool Loc690FD0(Guest& guest, RideId* rideToView, uint8_t* rideSeatToView, TileEl */ static bool GuestFindRideToLookAt(Guest& guest, uint8_t edge, RideId* rideToView, uint8_t* rideSeatToView) { - TileElement* tileElement; - auto surfaceElement = MapGetSurfaceElementAt(guest.NextLoc); - - tileElement = reinterpret_cast(surfaceElement); + TileElement* tileElement = reinterpret_cast(surfaceElement); if (tileElement == nullptr) { return false; diff --git a/src/openrct2/entity/Litter.cpp b/src/openrct2/entity/Litter.cpp index b0001a08b9..fb445f3a8b 100644 --- a/src/openrct2/entity/Litter.cpp +++ b/src/openrct2/entity/Litter.cpp @@ -25,12 +25,10 @@ bool EntityBase::Is() const static bool IsLocationLitterable(const CoordsXYZ& mapPos) { - TileElement* tileElement; - if (!MapIsLocationOwned(mapPos)) return false; - tileElement = MapGetFirstElementAt(mapPos); + TileElement* tileElement = MapGetFirstElementAt(mapPos); if (tileElement == nullptr) return false; do diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index 246e29eddf..47b8de33c0 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -1221,11 +1221,9 @@ void PeepUpdateCrowdNoise() } else { - int32_t volume; - // Formula to scale peeps to dB where peeps [0, 120] scales approximately logarithmically to [-3314, -150] dB/100 // 207360000 maybe related to DSBVOLUME_MIN which is -10,000 (dB/100) - volume = 120 - std::min(visiblePeeps, 120); + int32_t volume = 120 - std::min(visiblePeeps, 120); volume = volume * volume * volume * volume; volume = (viewport->zoom.ApplyInversedTo(207360000 - volume) - 207360000) / 65536 - 150; diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 4f838f079e..865a499c23 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -108,8 +108,7 @@ static bool InvalidArguments(bool* invalid, bool arguments); static int32_t ConsoleParseInt(const std::string& src, bool* valid) { utf8* end; - int32_t value; - value = static_cast(strtol(src.c_str(), &end, 10)); + int32_t value = static_cast(strtol(src.c_str(), &end, 10)); *valid = (*end == '\0'); return value; } @@ -117,8 +116,7 @@ static int32_t ConsoleParseInt(const std::string& src, bool* valid) static double ConsoleParseDouble(const std::string& src, bool* valid) { utf8* end; - double value; - value = strtod(src.c_str(), &end); + double value = strtod(src.c_str(), &end); *valid = (*end == '\0'); return value; } diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index 46b4e2646f..b798542a62 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -227,9 +227,7 @@ static constexpr float kWindowScrollLocations[][2] = { int32_t WindowGetScrollDataIndex(const WindowBase& w, WidgetIndex widget_index) { - int32_t i, result; - - result = 0; + int32_t i, result = 0; for (i = 0; i < widget_index; i++) { const auto& widget = w.widgets[i]; diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 7c684cd25a..29993e4eb3 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -345,8 +345,6 @@ namespace OpenRCT2::PathFinding static PathSearchResult FootpathElementNextInDirection( TileCoordsXYZ loc, PathElement* pathElement, Direction chosenDirection) { - TileElement* nextTileElement; - if (pathElement->IsSloped()) { if (pathElement->GetSlopeDirection() == chosenDirection) @@ -356,7 +354,7 @@ namespace OpenRCT2::PathFinding } loc += TileDirectionDelta[chosenDirection]; - nextTileElement = MapGetFirstElementAt(loc); + TileElement* nextTileElement = MapGetFirstElementAt(loc); do { if (nextTileElement == nullptr) diff --git a/src/openrct2/ride/Track.cpp b/src/openrct2/ride/Track.cpp index e376fbde65..a1caba833a 100644 --- a/src/openrct2/ride/Track.cpp +++ b/src/openrct2/ride/Track.cpp @@ -489,11 +489,10 @@ bool TrackCircuitIteratorsMatch(const TrackCircuitIterator* firstIt, const Track void TrackGetBack(const CoordsXYE& input, CoordsXYE* output) { - CoordsXYE lastTrack; + CoordsXYE lastTrack = input; TrackBeginEnd currentTrack; bool result; - lastTrack = input; do { result = TrackBlockGetPrevious(lastTrack, ¤tTrack); diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 5dfd5ab8a2..89cba1a8bd 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -4141,13 +4141,11 @@ void Vehicle::UpdateTopSpinOperating() */ void Vehicle::UpdateShowingFilm() { - int32_t currentTime, totalTime; - if (_vehicleBreakdown == 0) return; - totalTime = kRideFilmLength[sub_state]; - currentTime = current_time + 1; + int32_t totalTime = kRideFilmLength[sub_state]; + int32_t currentTime = current_time + 1; if (currentTime <= totalTime) { current_time = currentTime; diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index d00e3494e9..097c75179e 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -782,15 +782,14 @@ void FootpathChainRideQueue( RideId rideIndex, StationIndex entranceIndex, const CoordsXY& initialFootpathPos, TileElement* const initialTileElement, int32_t direction) { - TileElement *lastPathElement, *lastQueuePathElement; + TileElement* lastPathElement = nullptr; + TileElement* lastQueuePathElement = nullptr; auto tileElement = initialTileElement; auto curQueuePos = initialFootpathPos; auto lastPath = curQueuePos; int32_t baseZ = tileElement->GetBaseZ(); int32_t lastPathDirection = direction; - lastPathElement = nullptr; - lastQueuePathElement = nullptr; for (;;) { if (tileElement->GetType() == TileElementType::Path) diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index bd5a872e0d..bc63830d20 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -572,13 +572,12 @@ int16_t TileElementHeight(const CoordsXYZ& loc, uint8_t slope) int8_t quad = 0, quad_extra = 0; // which quadrant the element is in? // quad_extra is for extra height tiles - uint8_t xl, yl; // coordinates across this tile + // coordinates across this tile + uint8_t xl = loc.x & 0x1f; + uint8_t yl = loc.y & 0x1f; uint8_t TILE_SIZE = 32; - xl = loc.x & 0x1f; - yl = loc.y & 0x1f; - // Slope logic: // Each of the four bits in slope represents that corner being raised // slope == 15 (all four bits) is not used and slope == 0 is flat @@ -1769,13 +1768,11 @@ void MapInvalidateElement(const CoordsXY& elementPos, TileElement* tileElement) void MapInvalidateRegion(const CoordsXY& mins, const CoordsXY& maxs) { - int32_t x0, y0, x1, y1, left, right, top, bottom; - - x0 = mins.x + 16; - y0 = mins.y + 16; - - x1 = maxs.x + 16; - y1 = maxs.y + 16; + int32_t x0 = mins.x + 16; + int32_t y0 = mins.y + 16; + int32_t x1 = maxs.x + 16; + int32_t y1 = maxs.y + 16; + int32_t left, right, top, bottom; MapGetBoundingBox({ x0, y0, x1, y1 }, &left, &top, &right, &bottom); diff --git a/src/openrct2/world/Scenery.cpp b/src/openrct2/world/Scenery.cpp index 5b73605058..4186c60f23 100644 --- a/src/openrct2/world/Scenery.cpp +++ b/src/openrct2/world/Scenery.cpp @@ -126,9 +126,7 @@ int32_t LargeSceneryText::MeasureHeight(std::string_view text) const void SceneryUpdateTile(const CoordsXY& sceneryPos) { - TileElement* tileElement; - - tileElement = MapGetFirstElementAt(sceneryPos); + TileElement* tileElement = MapGetFirstElementAt(sceneryPos); if (tileElement == nullptr) return; do diff --git a/src/openrct2/world/Wall.cpp b/src/openrct2/world/Wall.cpp index 096c3bdee2..9c20e43cf9 100644 --- a/src/openrct2/world/Wall.cpp +++ b/src/openrct2/world/Wall.cpp @@ -44,9 +44,7 @@ void WallRemoveAtZ(const CoordsXYZ& wallPos) */ void WallRemoveIntersectingWalls(const CoordsXYRangedZ& wallPos, Direction direction) { - TileElement* tileElement; - - tileElement = MapGetFirstElementAt(wallPos); + TileElement* tileElement = MapGetFirstElementAt(wallPos); if (tileElement == nullptr) return; do @@ -125,9 +123,7 @@ uint8_t GetWallSlopeFromEdgeSlope(uint8_t Slope, uint8_t Edge) */ bool WallInTheWay(const CoordsXYRangedZ& fencePos, int32_t direction) { - TileElement* tileElement; - - tileElement = MapGetFirstElementAt(fencePos); + TileElement* tileElement = MapGetFirstElementAt(fencePos); if (tileElement == nullptr) return false; do