Codechange: make explicit when a TileIndex is cast to its basetype (#11190)

This prevents people accidentially assigning a TileIndex to a Date
or any other type they shouldn't.
This commit is contained in:
Patric Stout
2023-08-15 18:12:05 +02:00
committed by GitHub
parent 5d3f7939e2
commit 07730584d7
31 changed files with 120 additions and 105 deletions

View File

@@ -2143,7 +2143,7 @@ bool AfterLoadGame()
/* Delete small ufos heading for non-existing vehicles */
for (DisasterVehicle *v : DisasterVehicle::Iterate()) {
if (v->subtype == 2 /* ST_SMALL_UFO */ && v->state != 0) {
const Vehicle *u = Vehicle::GetIfValid(v->dest_tile);
const Vehicle *u = Vehicle::GetIfValid(static_cast<uint32_t>(v->dest_tile));
if (u == nullptr || u->type != VEH_ROAD || !RoadVehicle::From(u)->IsFrontEngine()) {
delete v;
}

View File

@@ -72,7 +72,7 @@ struct MAPTChunkHandler : ChunkHandler {
void Load() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
@@ -83,7 +83,7 @@ struct MAPTChunkHandler : ChunkHandler {
void Save() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
@@ -99,7 +99,7 @@ struct MAPHChunkHandler : ChunkHandler {
void Load() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
@@ -110,7 +110,7 @@ struct MAPHChunkHandler : ChunkHandler {
void Save() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
@@ -126,7 +126,7 @@ struct MAPOChunkHandler : ChunkHandler {
void Load() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
@@ -137,7 +137,7 @@ struct MAPOChunkHandler : ChunkHandler {
void Save() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
@@ -153,7 +153,7 @@ struct MAP2ChunkHandler : ChunkHandler {
void Load() const override
{
std::array<uint16_t, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE,
@@ -167,7 +167,7 @@ struct MAP2ChunkHandler : ChunkHandler {
void Save() const override
{
std::array<uint16_t, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
SlSetLength(static_cast<uint32_t>(size) * sizeof(uint16_t));
for (TileIndex i = 0; i != size;) {
@@ -183,7 +183,7 @@ struct M3LOChunkHandler : ChunkHandler {
void Load() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
@@ -194,7 +194,7 @@ struct M3LOChunkHandler : ChunkHandler {
void Save() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
@@ -210,7 +210,7 @@ struct M3HIChunkHandler : ChunkHandler {
void Load() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
@@ -221,7 +221,7 @@ struct M3HIChunkHandler : ChunkHandler {
void Save() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
@@ -237,7 +237,7 @@ struct MAP5ChunkHandler : ChunkHandler {
void Load() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
@@ -248,7 +248,7 @@ struct MAP5ChunkHandler : ChunkHandler {
void Save() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
@@ -264,7 +264,7 @@ struct MAPEChunkHandler : ChunkHandler {
void Load() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
if (IsSavegameVersionBefore(SLV_42)) {
for (TileIndex i = 0; i != size;) {
@@ -288,7 +288,7 @@ struct MAPEChunkHandler : ChunkHandler {
void Save() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
@@ -304,7 +304,7 @@ struct MAP7ChunkHandler : ChunkHandler {
void Load() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
@@ -315,7 +315,7 @@ struct MAP7ChunkHandler : ChunkHandler {
void Save() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
@@ -331,7 +331,7 @@ struct MAP8ChunkHandler : ChunkHandler {
void Load() const override
{
std::array<uint16_t, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16);
@@ -342,7 +342,7 @@ struct MAP8ChunkHandler : ChunkHandler {
void Save() const override
{
std::array<uint16_t, MAP_SL_BUF_SIZE> buf;
TileIndex size = Map::Size();
uint size = Map::Size();
SlSetLength(static_cast<uint32_t>(size) * sizeof(uint16_t));
for (TileIndex i = 0; i != size;) {