diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index e91fe59fc5..8872f8db36 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -527,7 +527,7 @@ private: EntryList* entries = GetEntryList(objectType); // Check if there are spare entries available - size_t maxEntries = (size_t)object_entry_group_counts[objectType]; + size_t maxEntries = static_cast(object_entry_group_counts[objectType]); if (entries != nullptr && entries->GetCount() < maxEntries) { entries->GetOrAddEntry(objectName); @@ -1115,7 +1115,7 @@ private: rct1_vehicle* srcVehicle = &_s4.sprites[i].vehicle; if (srcVehicle->x != LOCATION_NULL) { - Vehicle* vehicle = (Vehicle*)create_sprite(SPRITE_IDENTIFIER_VEHICLE); + Vehicle* vehicle = reinterpret_cast(create_sprite(SPRITE_IDENTIFIER_VEHICLE)); spriteIndexMap[i] = vehicle->sprite_index; vehicles.push_back(vehicle); @@ -1330,7 +1330,7 @@ private: if (_s4.sprites[i].unknown.sprite_identifier == SPRITE_IDENTIFIER_PEEP) { rct1_peep* srcPeep = &_s4.sprites[i].peep; - Peep* peep = (Peep*)create_sprite(SPRITE_IDENTIFIER_PEEP); + Peep* peep = reinterpret_cast(create_sprite(SPRITE_IDENTIFIER_PEEP)); spriteIndexMap[i] = peep->sprite_index; ImportPeep(peep, srcPeep); @@ -1341,7 +1341,7 @@ private: rct_sprite* sprite = get_sprite(i); if (sprite->generic.sprite_identifier == SPRITE_IDENTIFIER_VEHICLE) { - Vehicle* vehicle = (Vehicle*)sprite; + Vehicle* vehicle = reinterpret_cast(sprite); FixVehiclePeepLinks(vehicle, spriteIndexMap); } } @@ -1513,7 +1513,7 @@ private: { auto srcThought = &src->thoughts[i]; auto dstThought = &dst->thoughts[i]; - dstThought->type = (PeepThoughtType)srcThought->type; + dstThought->type = static_cast(srcThought->type); dstThought->item = srcThought->type; dstThought->freshness = srcThought->freshness; dstThought->fresh_timeout = srcThought->fresh_timeout; @@ -1630,7 +1630,7 @@ private: { const auto* srcLitter = &sprite.litter; - Litter* litter = (Litter*)create_sprite(SPRITE_IDENTIFIER_LITTER); + Litter* litter = reinterpret_cast(create_sprite(SPRITE_IDENTIFIER_LITTER)); litter->sprite_identifier = srcLitter->sprite_identifier; litter->type = srcLitter->type; @@ -1655,7 +1655,7 @@ private: if (sprite.unknown.sprite_identifier == SPRITE_IDENTIFIER_MISC) { rct1_unk_sprite* src = &sprite.unknown; - SpriteGeneric* dst = (SpriteGeneric*)create_sprite(SPRITE_IDENTIFIER_MISC); + SpriteGeneric* dst = reinterpret_cast(create_sprite(SPRITE_IDENTIFIER_MISC)); dst->sprite_identifier = src->sprite_identifier; dst->type = src->type; dst->flags = src->flags; @@ -1669,10 +1669,10 @@ private: switch (src->type) { case SPRITE_MISC_STEAM_PARTICLE: - ImportSteamParticle((SteamParticle*)dst, (SteamParticle*)src); + ImportSteamParticle(reinterpret_cast(dst), reinterpret_cast(src)); break; case SPRITE_MISC_MONEY_EFFECT: - ImportMoneyEffect((MoneyEffect*)dst, (MoneyEffect*)src); + ImportMoneyEffect(reinterpret_cast(dst), reinterpret_cast(src)); break; case SPRITE_MISC_CRASHED_VEHICLE_PARTICLE: break; @@ -1683,13 +1683,14 @@ private: case SPRITE_MISC_EXPLOSION_FLARE: break; case SPRITE_MISC_JUMPING_FOUNTAIN_WATER: - ImportJumpingFountainWater((JumpingFountain*)dst, (JumpingFountain*)src); + ImportJumpingFountainWater( + reinterpret_cast(dst), reinterpret_cast(src)); break; case SPRITE_MISC_BALLOON: - ImportBalloon((Balloon*)dst, (Balloon*)src); + ImportBalloon(reinterpret_cast(dst), reinterpret_cast(src)); break; case SPRITE_MISC_DUCK: - ImportDuck((Duck*)dst, (Duck*)src); + ImportDuck(reinterpret_cast(dst), reinterpret_cast(src)); break; } @@ -1814,7 +1815,7 @@ private: if (_s4.marketing_status[i] & CAMPAIGN_ACTIVE_FLAG) { MarketingCampaign campaign; - campaign.Type = (uint8_t)i; + campaign.Type = static_cast(i); campaign.WeeksLeft = _s4.marketing_status[i] & ~CAMPAIGN_ACTIVE_FLAG; if (campaign.Type == ADVERTISING_CAMPAIGN_RIDE_FREE || campaign.Type == ADVERTISING_CAMPAIGN_RIDE) { @@ -2540,7 +2541,7 @@ private: ResearchItem tmpResearchItem = {}; ConvertResearchEntry(&tmpResearchItem, researchItem, researchType); - dst->Assoc = (uint32_t)tmpResearchItem.rawValue; + dst->Assoc = static_cast(tmpResearchItem.rawValue); } else { diff --git a/src/openrct2/rct12/RCT12.cpp b/src/openrct2/rct12/RCT12.cpp index 64a529419f..d42fc3f6ba 100644 --- a/src/openrct2/rct12/RCT12.cpp +++ b/src/openrct2/rct12/RCT12.cpp @@ -335,7 +335,7 @@ colour_t RCT12SmallSceneryElement::GetSecondaryColour() const bool RCT12SmallSceneryElement::NeedsSupports() const { - return (bool)(colour_1 & MAP_ELEM_SMALL_SCENERY_COLOUR_FLAG_NEEDS_SUPPORTS); + return colour_1 & MAP_ELEM_SMALL_SCENERY_COLOUR_FLAG_NEEDS_SUPPORTS; } uint32_t RCT12LargeSceneryElement::GetEntryIndex() const diff --git a/src/openrct2/rct12/RCT12.h b/src/openrct2/rct12/RCT12.h index f67fbaee4e..f0340065a3 100644 --- a/src/openrct2/rct12/RCT12.h +++ b/src/openrct2/rct12/RCT12.h @@ -276,6 +276,7 @@ struct RCT12TileElement : public RCT12TileElementBase uint8_t pad_04[4]; template TType* as() const { + // TODO: CAST-IMPROVEMENT-NEEDED return (RCT12TileElementType)GetType() == TClass ? (TType*)this : nullptr; } diff --git a/src/openrct2/rct12/SawyerChunkReader.cpp b/src/openrct2/rct12/SawyerChunkReader.cpp index 5764a0f917..90304cdbe8 100644 --- a/src/openrct2/rct12/SawyerChunkReader.cpp +++ b/src/openrct2/rct12/SawyerChunkReader.cpp @@ -84,14 +84,14 @@ std::shared_ptr SawyerChunkReader::ReadChunk() throw SawyerChunkException(EXCEPTION_MSG_CORRUPT_CHUNK_SIZE); } - auto buffer = (uint8_t*)AllocateLargeTempBuffer(); + auto buffer = static_cast(AllocateLargeTempBuffer()); size_t uncompressedLength = DecodeChunk(buffer, MAX_UNCOMPRESSED_CHUNK_SIZE, compressedData.get(), header); if (uncompressedLength == 0) { throw SawyerChunkException(EXCEPTION_MSG_ZERO_SIZED_CHUNK); } - buffer = (uint8_t*)FinaliseLargeTempBuffer(buffer, uncompressedLength); - return std::make_shared((SAWYER_ENCODING)header.encoding, buffer, uncompressedLength); + buffer = static_cast(FinaliseLargeTempBuffer(buffer, uncompressedLength)); + return std::make_shared(static_cast(header.encoding), buffer, uncompressedLength); } default: throw SawyerChunkException(EXCEPTION_MSG_INVALID_CHUNK_ENCODING); @@ -124,14 +124,14 @@ std::shared_ptr SawyerChunkReader::ReadChunkTrack() throw SawyerChunkException(EXCEPTION_MSG_CORRUPT_CHUNK_SIZE); } - auto buffer = (uint8_t*)AllocateLargeTempBuffer(); + auto buffer = static_cast(AllocateLargeTempBuffer()); sawyercoding_chunk_header header{ CHUNK_ENCODING_RLE, compressedDataLength }; size_t uncompressedLength = DecodeChunk(buffer, MAX_UNCOMPRESSED_CHUNK_SIZE, compressedData.get(), header); if (uncompressedLength == 0) { throw SawyerChunkException(EXCEPTION_MSG_ZERO_SIZED_CHUNK); } - buffer = (uint8_t*)FinaliseLargeTempBuffer(buffer, uncompressedLength); + buffer = static_cast(FinaliseLargeTempBuffer(buffer, uncompressedLength)); return std::make_shared(SAWYER_ENCODING::RLE, buffer, uncompressedLength); } catch (const std::exception&) @@ -145,7 +145,7 @@ std::shared_ptr SawyerChunkReader::ReadChunkTrack() void SawyerChunkReader::ReadChunk(void* dst, size_t length) { auto chunk = ReadChunk(); - auto chunkData = (const uint8_t*)chunk->GetData(); + auto chunkData = static_cast(chunk->GetData()); auto chunkLength = chunk->GetLength(); if (chunkLength > length) { @@ -157,7 +157,7 @@ void SawyerChunkReader::ReadChunk(void* dst, size_t length) auto remainingLength = length - chunkLength; if (remainingLength > 0) { - auto offset = (uint8_t*)dst + chunkLength; + auto offset = static_cast(dst) + chunkLength; std::fill_n(offset, remainingLength, 0x00); } } @@ -245,7 +245,7 @@ size_t SawyerChunkReader::DecodeChunkRLE(void* dst, size_t dstCapacity, const vo i += rleCodeByte + 1; } } - return (uintptr_t)dst8 - (uintptr_t)dst; + return reinterpret_cast(dst8) - reinterpret_cast(dst); } size_t SawyerChunkReader::DecodeChunkRepeat(void* dst, size_t dstCapacity, const void* src, size_t srcLength) @@ -262,7 +262,7 @@ size_t SawyerChunkReader::DecodeChunkRepeat(void* dst, size_t dstCapacity, const else { size_t count = (src8[i] & 7) + 1; - const uint8_t* copySrc = dst8 + (int32_t)(src8[i] >> 3) - 32; + const uint8_t* copySrc = dst8 + static_cast(src8[i] >> 3) - 32; if (dst8 + count >= dstEnd || copySrc + count >= dstEnd) { @@ -273,7 +273,7 @@ size_t SawyerChunkReader::DecodeChunkRepeat(void* dst, size_t dstCapacity, const dst8 += count; } } - return (uintptr_t)dst8 - (uintptr_t)dst; + return reinterpret_cast(dst8) - reinterpret_cast(dst); } size_t SawyerChunkReader::DecodeChunkRotate(void* dst, size_t dstCapacity, const void* src, size_t srcLength) @@ -315,7 +315,7 @@ void* SawyerChunkReader::FinaliseLargeTempBuffer(void* buffer, size_t len) std::memcpy(finalBuffer, buffer, len); HeapFree(GetProcessHeap(), 0, buffer); #else - auto finalBuffer = (uint8_t*)std::realloc(buffer, len); + auto finalBuffer = static_cast(std::realloc(buffer, len)); #endif if (finalBuffer == nullptr) { diff --git a/src/openrct2/rct12/SawyerChunkWriter.cpp b/src/openrct2/rct12/SawyerChunkWriter.cpp index 306b774b3e..0c09d85e44 100644 --- a/src/openrct2/rct12/SawyerChunkWriter.cpp +++ b/src/openrct2/rct12/SawyerChunkWriter.cpp @@ -28,11 +28,11 @@ void SawyerChunkWriter::WriteChunk(const SawyerChunk* chunk) void SawyerChunkWriter::WriteChunk(const void* src, size_t length, SAWYER_ENCODING encoding) { sawyercoding_chunk_header header; - header.encoding = (uint8_t)encoding; - header.length = (uint32_t)length; + header.encoding = static_cast(encoding); + header.length = static_cast(length); auto data = std::make_unique(MAX_COMPRESSED_CHUNK_SIZE); - size_t dataLength = sawyercoding_write_chunk_buffer(data.get(), (const uint8_t*)src, header); + size_t dataLength = sawyercoding_write_chunk_buffer(data.get(), static_cast(src), header); _stream->Write(data.get(), dataLength); } @@ -92,7 +92,7 @@ static size_t EncodeChunkRLE(const uint8_t* src_buffer, uint8_t* dst_buffer, siz void SawyerChunkWriter::WriteChunkTrack(const void* src, size_t length) { auto data = std::make_unique(MAX_COMPRESSED_CHUNK_SIZE); - size_t dataLength = EncodeChunkRLE((const uint8_t*)src, data.get(), length); + size_t dataLength = EncodeChunkRLE(static_cast(src), data.get(), length); uint32_t checksum = 0; for (size_t i = 0; i < dataLength; i++) diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index 8e17cb5409..b88a35d2a8 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -435,8 +435,8 @@ void S6Exporter::ExportPeepSpawns() { if (gPeepSpawns.size() > i) { - _s6.peep_spawns[i] = { (uint16_t)gPeepSpawns[i].x, (uint16_t)gPeepSpawns[i].y, (uint8_t)(gPeepSpawns[i].z / 16), - gPeepSpawns[i].direction }; + _s6.peep_spawns[i] = { static_cast(gPeepSpawns[i].x), static_cast(gPeepSpawns[i].y), + static_cast(gPeepSpawns[i].z / 16), gPeepSpawns[i].direction }; } else { @@ -529,7 +529,8 @@ void S6Exporter::ExportRide(rct2_ride* dst, const Ride* src) } else { - log_warning("Unable to allocate user string for ride #%d (%s).", (int)src->id, src->custom_name.c_str()); + log_warning( + "Unable to allocate user string for ride #%d (%s).", static_cast(src->id), src->custom_name.c_str()); } } if (useDefaultName) @@ -569,13 +570,13 @@ void S6Exporter::ExportRide(rct2_ride* dst, const Ride* src) if (entrance.isNull()) dst->entrances[i].setNull(); else - dst->entrances[i] = { (uint8_t)entrance.x, (uint8_t)entrance.y }; + dst->entrances[i] = { static_cast(entrance.x), static_cast(entrance.y) }; TileCoordsXYZD exit = ride_get_exit_location(src, i); if (exit.isNull()) dst->exits[i].setNull(); else - dst->exits[i] = { (uint8_t)exit.x, (uint8_t)exit.y }; + dst->exits[i] = { static_cast(exit.x), static_cast(exit.y) }; dst->last_peep_in_queue[i] = src->stations[i].LastPeepInQueue; @@ -643,9 +644,9 @@ void S6Exporter::ExportRide(rct2_ride* dst, const Ride* src) dst->turn_count_banked = src->turn_count_banked; dst->turn_count_sloped = src->turn_count_sloped; if (dst->type == RIDE_TYPE_MINI_GOLF) - dst->inversions = (uint8_t)std::min(src->holes, RCT12_MAX_GOLF_HOLES); + dst->inversions = static_cast(std::min(src->holes, RCT12_MAX_GOLF_HOLES)); else - dst->inversions = (uint8_t)std::min(src->inversions, RCT12_MAX_INVERSIONS); + dst->inversions = static_cast(std::min(src->inversions, RCT12_MAX_INVERSIONS)); dst->inversions |= (src->sheltered_eighths << 5); dst->drops = src->drops; dst->start_drop_height = src->start_drop_height; @@ -856,7 +857,7 @@ void S6Exporter::ExportResearchedRideTypes() { int32_t quadIndex = rideType >> 5; int32_t bitIndex = rideType & 0x1F; - _s6.researched_ride_types[quadIndex] |= (uint32_t)1 << bitIndex; + _s6.researched_ride_types[quadIndex] |= 1UL << bitIndex; } } } @@ -871,7 +872,7 @@ void S6Exporter::ExportResearchedRideEntries() { int32_t quadIndex = rideEntryIndex >> 5; int32_t bitIndex = rideEntryIndex & 0x1F; - _s6.researched_ride_entries[quadIndex] |= (uint32_t)1 << bitIndex; + _s6.researched_ride_entries[quadIndex] |= 1UL << bitIndex; } } } @@ -893,7 +894,7 @@ void S6Exporter::ExportResearchedSceneryItems() { int32_t quadIndex = sceneryEntryIndex >> 5; int32_t bitIndex = sceneryEntryIndex & 0x1F; - _s6.researched_scenery_items[quadIndex] |= (uint32_t)1 << bitIndex; + _s6.researched_scenery_items[quadIndex] |= 1UL << bitIndex; } } } @@ -1007,7 +1008,7 @@ void S6Exporter::ExportSpriteVehicle(RCT2SpriteVehicle* dst, const Vehicle* src) { const auto* ride = get_ride(src->ride); - ExportSpriteCommonProperties(dst, (const SpriteBase*)src); + ExportSpriteCommonProperties(dst, static_cast(src)); dst->vehicle_sprite_type = src->vehicle_sprite_type; dst->bank_rotation = src->bank_rotation; dst->remaining_distance = src->remaining_distance; @@ -1091,7 +1092,7 @@ void S6Exporter::ExportSpriteVehicle(RCT2SpriteVehicle* dst, const Vehicle* src) void S6Exporter::ExportSpritePeep(RCT2SpritePeep* dst, const Peep* src) { - ExportSpriteCommonProperties(dst, (const SpriteBase*)src); + ExportSpriteCommonProperties(dst, static_cast(src)); auto generateName = true; if (src->name != nullptr) @@ -1105,7 +1106,8 @@ void S6Exporter::ExportSpritePeep(RCT2SpritePeep* dst, const Peep* src) else { log_warning( - "Unable to allocate user string for peep #%d (%s) during S6 export.", (int)src->sprite_index, src->name); + "Unable to allocate user string for peep #%d (%s) during S6 export.", static_cast(src->sprite_index), + src->name); } } if (generateName) @@ -1135,10 +1137,10 @@ void S6Exporter::ExportSpritePeep(RCT2SpritePeep* dst, const Peep* src) dst->next_z = src->NextLoc.z / COORDS_Z_STEP; dst->next_flags = src->next_flags; dst->outside_of_park = src->outside_of_park; - dst->state = (uint8_t)src->state; + dst->state = static_cast(src->state); dst->sub_state = src->sub_state; - dst->sprite_type = (uint8_t)src->sprite_type; - dst->peep_type = (uint8_t)src->type; + dst->sprite_type = static_cast(src->sprite_type); + dst->peep_type = static_cast(src->type); dst->no_of_rides = src->no_of_rides; dst->tshirt_colour = src->tshirt_colour; dst->trousers_colour = src->trousers_colour; @@ -1174,10 +1176,10 @@ void S6Exporter::ExportSpritePeep(RCT2SpritePeep* dst, const Peep* src) dst->current_train = src->current_train; dst->time_to_sitdown = src->time_to_sitdown; dst->special_sprite = src->special_sprite; - dst->action_sprite_type = (uint8_t)src->action_sprite_type; - dst->next_action_sprite_type = (uint8_t)src->next_action_sprite_type; + dst->action_sprite_type = static_cast(src->action_sprite_type); + dst->next_action_sprite_type = static_cast(src->next_action_sprite_type); dst->action_sprite_image_offset = src->action_sprite_image_offset; - dst->action = (uint8_t)src->action; + dst->action = static_cast(src->action); dst->action_frame = src->action_frame; dst->step_progress = src->step_progress; dst->next_in_queue = src->next_in_queue; @@ -1199,7 +1201,7 @@ void S6Exporter::ExportSpritePeep(RCT2SpritePeep* dst, const Peep* src) { auto srcThought = &src->thoughts[i]; auto dstThought = &dst->thoughts[i]; - dstThought->type = (uint8_t)srcThought->type; + dstThought->type = static_cast(srcThought->type); dstThought->item = srcThought->item; dstThought->freshness = srcThought->freshness; dstThought->fresh_timeout = srcThought->fresh_timeout; @@ -1247,16 +1249,16 @@ void S6Exporter::ExportSpriteMisc(RCT12SpriteBase* cdst, const SpriteBase* csrc) { case SPRITE_MISC_STEAM_PARTICLE: { - auto src = (const SteamParticle*)csrc; - auto dst = (RCT12SpriteSteamParticle*)cdst; + auto src = static_cast(csrc); + auto dst = static_cast(cdst); dst->time_to_move = src->time_to_move; dst->frame = src->frame; break; } case SPRITE_MISC_MONEY_EFFECT: { - auto src = (const MoneyEffect*)csrc; - auto dst = (RCT12SpriteMoneyEffect*)cdst; + auto src = static_cast(csrc); + auto dst = static_cast(cdst); dst->move_delay = src->move_delay; dst->num_movements = src->num_movements; dst->vertical = src->vertical; @@ -1267,8 +1269,8 @@ void S6Exporter::ExportSpriteMisc(RCT12SpriteBase* cdst, const SpriteBase* csrc) } case SPRITE_MISC_CRASHED_VEHICLE_PARTICLE: { - auto src = (const VehicleCrashParticle*)csrc; - auto dst = (RCT12SpriteCrashedVehicleParticle*)cdst; + auto src = static_cast(csrc); + auto dst = static_cast(cdst); dst->frame = src->frame; dst->time_to_live = src->time_to_live; dst->frame = src->frame; @@ -1287,16 +1289,16 @@ void S6Exporter::ExportSpriteMisc(RCT12SpriteBase* cdst, const SpriteBase* csrc) case SPRITE_MISC_EXPLOSION_FLARE: case SPRITE_MISC_CRASH_SPLASH: { - auto src = (const SpriteGeneric*)csrc; - auto dst = (RCT12SpriteParticle*)cdst; + auto src = static_cast(csrc); + auto dst = static_cast(cdst); dst->frame = src->frame; break; } case SPRITE_MISC_JUMPING_FOUNTAIN_WATER: case SPRITE_MISC_JUMPING_FOUNTAIN_SNOW: { - auto* src = (const JumpingFountain*)csrc; - auto* dst = (RCT12SpriteJumpingFountain*)cdst; + auto* src = static_cast(csrc); + auto* dst = static_cast(cdst); dst->num_ticks_alive = src->NumTicksAlive; dst->frame = src->frame; dst->fountain_flags = src->FountainFlags; @@ -1308,8 +1310,8 @@ void S6Exporter::ExportSpriteMisc(RCT12SpriteBase* cdst, const SpriteBase* csrc) } case SPRITE_MISC_BALLOON: { - auto src = (const Balloon*)csrc; - auto dst = (RCT12SpriteBalloon*)cdst; + auto src = static_cast(csrc); + auto dst = static_cast(cdst); dst->popped = src->popped; dst->time_to_move = src->time_to_move; dst->frame = src->frame; @@ -1318,8 +1320,8 @@ void S6Exporter::ExportSpriteMisc(RCT12SpriteBase* cdst, const SpriteBase* csrc) } case SPRITE_MISC_DUCK: { - auto src = (const Duck*)csrc; - auto dst = (RCT12SpriteDuck*)cdst; + auto src = static_cast(csrc); + auto dst = static_cast(cdst); dst->frame = src->frame; dst->target_x = src->target_x; dst->target_y = src->target_y; @@ -1391,7 +1393,7 @@ void S6Exporter::ExportMapAnimations() { const auto& mapAnimations = GetMapAnimations(); auto numAnimations = std::min(mapAnimations.size(), std::size(_s6.map_animations)); - _s6.num_map_animations = (uint16_t)numAnimations; + _s6.num_map_animations = static_cast(numAnimations); for (size_t i = 0; i < numAnimations; i++) { const auto& src = mapAnimations[i]; @@ -1416,7 +1418,7 @@ void S6Exporter::ExportTileElements() } else { - auto tileElementType = (RCT12TileElementType)src->GetType(); + auto tileElementType = static_cast(src->GetType()); if (tileElementType == RCT12TileElementType::Corrupt || tileElementType == RCT12TileElementType::EightCarsCorrupt14 || tileElementType == RCT12TileElementType::EightCarsCorrupt15) std::memcpy(dst, src, sizeof(*dst)); @@ -1617,7 +1619,7 @@ std::optional S6Exporter::AllocateUserString(const std::string_view& v if (nextId < RCT12_MAX_USER_STRINGS) { _userStrings.emplace_back(value); - return (uint16_t)(USER_STRING_START + nextId); + return static_cast(USER_STRING_START + nextId); } return {}; } @@ -1634,7 +1636,7 @@ static std::string GetTruncatedRCT2String(const std::string_view& src) rct2encoded.resize(RCT12_USER_STRING_MAX_LENGTH - 1); for (size_t i = 0; i < rct2encoded.size(); i++) { - if (rct2encoded[i] == (char)(uint8_t)0xFF) + if (rct2encoded[i] == static_cast(static_cast(0xFF))) { if (i > RCT12_USER_STRING_MAX_LENGTH - 4) { diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 1139ce3d6e..9349c0b556 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -841,7 +841,7 @@ public: { int32_t quadIndex = rideType >> 5; int32_t bitIndex = rideType & 0x1F; - bool invented = (_s6.researched_ride_types[quadIndex] & ((uint32_t)1 << bitIndex)); + bool invented = (_s6.researched_ride_types[quadIndex] & (1UL << bitIndex)); if (invented) ride_type_set_invented(rideType); @@ -856,7 +856,7 @@ public: { int32_t quadIndex = rideEntryIndex >> 5; int32_t bitIndex = rideEntryIndex & 0x1F; - bool invented = (_s6.researched_ride_entries[quadIndex] & ((uint32_t)1 << bitIndex)); + bool invented = (_s6.researched_ride_entries[quadIndex] & (1UL << bitIndex)); if (invented) ride_entry_set_invented(rideEntryIndex); @@ -871,7 +871,7 @@ public: { int32_t quadIndex = sceneryEntryIndex >> 5; int32_t bitIndex = sceneryEntryIndex & 0x1F; - bool invented = (_s6.researched_scenery_items[quadIndex] & ((uint32_t)1 << bitIndex)); + bool invented = (_s6.researched_scenery_items[quadIndex] & (1UL << bitIndex)); if (invented) { @@ -1018,7 +1018,7 @@ public: } else { - auto tileElementType = (RCT12TileElementType)src->GetType(); + auto tileElementType = static_cast(src->GetType()); // Todo: replace with setting invisibility bit if (tileElementType == RCT12TileElementType::Corrupt || tileElementType == RCT12TileElementType::EightCarsCorrupt14 @@ -1243,7 +1243,7 @@ public: if (_s6.campaign_weeks_left[i] & CAMPAIGN_ACTIVE_FLAG) { MarketingCampaign campaign{}; - campaign.Type = (uint8_t)i; + campaign.Type = static_cast(i); campaign.WeeksLeft = _s6.campaign_weeks_left[i] & ~(CAMPAIGN_ACTIVE_FLAG | CAMPAIGN_FIRST_WEEK_FLAG); if ((_s6.campaign_weeks_left[i] & CAMPAIGN_FIRST_WEEK_FLAG) != 0) { @@ -1286,7 +1286,7 @@ public: switch (src->unknown.sprite_identifier) { case SPRITE_IDENTIFIER_NULL: - ImportSpriteCommonProperties((SpriteBase*)dst, &src->unknown); + ImportSpriteCommonProperties(reinterpret_cast(dst), &src->unknown); break; case SPRITE_IDENTIFIER_VEHICLE: ImportSpriteVehicle(&dst->vehicle, &src->vehicle); @@ -1301,7 +1301,7 @@ public: ImportSpriteLitter(&dst->litter, &src->litter); break; default: - ImportSpriteCommonProperties((SpriteBase*)dst, (const RCT12SpriteBase*)src); + ImportSpriteCommonProperties(reinterpret_cast(dst), reinterpret_cast(src)); log_warning("Sprite identifier %d can not be imported.", src->unknown.sprite_identifier); break; } @@ -1311,7 +1311,7 @@ public: { const auto& ride = _s6.rides[src->ride]; - ImportSpriteCommonProperties((SpriteBase*)dst, src); + ImportSpriteCommonProperties(static_cast(dst), src); dst->vehicle_sprite_type = src->vehicle_sprite_type; dst->bank_rotation = src->bank_rotation; dst->remaining_distance = src->remaining_distance; @@ -1394,7 +1394,7 @@ public: void ImportSpritePeep(Peep* dst, const RCT2SpritePeep* src) { - ImportSpriteCommonProperties((SpriteBase*)dst, src); + ImportSpriteCommonProperties(static_cast(dst), src); if (is_user_string_id(src->name_string_idx)) { dst->SetName(GetUserString(src->name_string_idx)); @@ -1402,10 +1402,10 @@ public: dst->NextLoc = { src->next_x, src->next_y, src->next_z * COORDS_Z_STEP }; dst->next_flags = src->next_flags; dst->outside_of_park = src->outside_of_park; - dst->state = (PeepState)src->state; + dst->state = static_cast(src->state); dst->sub_state = src->sub_state; - dst->sprite_type = (PeepSpriteType)src->sprite_type; - dst->type = (PeepType)src->peep_type; + dst->sprite_type = static_cast(src->sprite_type); + dst->type = static_cast(src->peep_type); dst->no_of_rides = src->no_of_rides; dst->tshirt_colour = src->tshirt_colour; dst->trousers_colour = src->trousers_colour; @@ -1441,10 +1441,10 @@ public: dst->current_train = src->current_train; dst->time_to_sitdown = src->time_to_sitdown; dst->special_sprite = src->special_sprite; - dst->action_sprite_type = (PeepActionSpriteType)src->action_sprite_type; - dst->next_action_sprite_type = (PeepActionSpriteType)src->next_action_sprite_type; + dst->action_sprite_type = static_cast(src->action_sprite_type); + dst->next_action_sprite_type = static_cast(src->next_action_sprite_type); dst->action_sprite_image_offset = src->action_sprite_image_offset; - dst->action = (PeepActionType)src->action; + dst->action = static_cast(src->action); dst->action_frame = src->action_frame; dst->step_progress = src->step_progress; dst->next_in_queue = src->next_in_queue; @@ -1466,7 +1466,7 @@ public: { auto srcThought = &src->thoughts[i]; auto dstThought = &dst->thoughts[i]; - dstThought->type = (PeepThoughtType)srcThought->type; + dstThought->type = static_cast(srcThought->type); dstThought->item = srcThought->item; dstThought->freshness = srcThought->freshness; dstThought->fresh_timeout = srcThought->fresh_timeout; @@ -1514,16 +1514,16 @@ public: { case SPRITE_MISC_STEAM_PARTICLE: { - auto src = (const RCT12SpriteSteamParticle*)csrc; - auto dst = (SteamParticle*)cdst; + auto src = static_cast(csrc); + auto dst = static_cast(cdst); dst->time_to_move = src->time_to_move; dst->frame = src->frame; break; } case SPRITE_MISC_MONEY_EFFECT: { - auto src = (const RCT12SpriteMoneyEffect*)csrc; - auto dst = (MoneyEffect*)cdst; + auto src = static_cast(csrc); + auto dst = static_cast(cdst); dst->move_delay = src->move_delay; dst->num_movements = src->num_movements; dst->vertical = src->vertical; @@ -1534,8 +1534,8 @@ public: } case SPRITE_MISC_CRASHED_VEHICLE_PARTICLE: { - auto src = (const RCT12SpriteCrashedVehicleParticle*)csrc; - auto dst = (VehicleCrashParticle*)cdst; + auto src = static_cast(csrc); + auto dst = static_cast(cdst); dst->frame = src->frame; dst->time_to_live = src->time_to_live; dst->frame = src->frame; @@ -1554,16 +1554,16 @@ public: case SPRITE_MISC_EXPLOSION_FLARE: case SPRITE_MISC_CRASH_SPLASH: { - auto src = (const RCT12SpriteParticle*)csrc; - auto dst = (SpriteGeneric*)cdst; + auto src = static_cast(csrc); + auto dst = static_cast(cdst); dst->frame = src->frame; break; } case SPRITE_MISC_JUMPING_FOUNTAIN_WATER: case SPRITE_MISC_JUMPING_FOUNTAIN_SNOW: { - auto* src = (const RCT12SpriteJumpingFountain*)csrc; - auto* dst = (JumpingFountain*)cdst; + auto* src = static_cast(csrc); + auto* dst = static_cast(cdst); dst->NumTicksAlive = src->num_ticks_alive; dst->frame = src->frame; dst->FountainFlags = src->fountain_flags; @@ -1574,8 +1574,8 @@ public: } case SPRITE_MISC_BALLOON: { - auto src = (const RCT12SpriteBalloon*)csrc; - auto dst = (Balloon*)cdst; + auto src = static_cast(csrc); + auto dst = static_cast(cdst); dst->popped = src->popped; dst->time_to_move = src->time_to_move; dst->frame = src->frame; @@ -1584,8 +1584,8 @@ public: } case SPRITE_MISC_DUCK: { - auto src = (const RCT12SpriteDuck*)csrc; - auto dst = (Duck*)cdst; + auto src = static_cast(csrc); + auto dst = static_cast(cdst); dst->frame = src->frame; dst->target_x = src->target_x; dst->target_y = src->target_y; diff --git a/src/openrct2/rct2/T6Exporter.cpp b/src/openrct2/rct2/T6Exporter.cpp index e7e60d6320..044f15ae83 100644 --- a/src/openrct2/rct2/T6Exporter.cpp +++ b/src/openrct2/rct2/T6Exporter.cpp @@ -107,7 +107,7 @@ bool T6Exporter::SaveTrack(IStream* stream) for (const auto& entranceElement : _trackDesign->entrance_elements) { - tempStream.WriteValue(entranceElement.z == -1 ? (uint8_t)0x80 : entranceElement.z); + tempStream.WriteValue(entranceElement.z == -1 ? static_cast(0x80) : entranceElement.z); tempStream.WriteValue(entranceElement.direction | (entranceElement.isExit << 7)); tempStream.WriteValue(entranceElement.x); tempStream.WriteValue(entranceElement.y); diff --git a/src/openrct2/rct2/T6Importer.cpp b/src/openrct2/rct2/T6Importer.cpp index 6e995a4df6..a8c943f014 100644 --- a/src/openrct2/rct2/T6Importer.cpp +++ b/src/openrct2/rct2/T6Importer.cpp @@ -173,7 +173,7 @@ public: _stream.SetPosition(_stream.GetPosition() - 1); _stream.Read(&t6EntranceElement, sizeof(rct_td6_entrance_element)); TrackDesignEntranceElement entranceElement{}; - entranceElement.z = (t6EntranceElement.z == (int8_t)(uint8_t)0x80) ? -1 : t6EntranceElement.z; + entranceElement.z = (t6EntranceElement.z == -128) ? -1 : t6EntranceElement.z; entranceElement.direction = t6EntranceElement.direction & 0x7F; entranceElement.x = t6EntranceElement.x; entranceElement.y = t6EntranceElement.y;