From a2e1212f9a6420774935a29e7e0d7b55a7aa3c1f Mon Sep 17 00:00:00 2001 From: KJeff01 Date: Fri, 12 Apr 2024 11:24:15 -0500 Subject: [PATCH] Create `makeTileRubbleTexture()` to set tiles to a rubble texture --- src/feature.cpp | 16 +++++++--------- src/map.h | 7 +++++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/feature.cpp b/src/feature.cpp index afbdc557576..0790101a490 100644 --- a/src/feature.cpp +++ b/src/feature.cpp @@ -546,7 +546,9 @@ bool destroyFeature(FEATURE *psDel, unsigned impactTime) { for (int width = 0; width < b.size.x; ++width) { - MAPTILE *psTile = mapTile(b.map.x + width, b.map.y + breadth); + const unsigned int x = b.map.x + width; + const unsigned int y = b.map.y + breadth; + MAPTILE *psTile = mapTile(x, y); // stops water texture changing for underwater features if (terrainType(psTile) != TER_WATER) { @@ -555,22 +557,18 @@ bool destroyFeature(FEATURE *psDel, unsigned impactTime) /* Clear feature bits */ if (isUrban) { - psTile->texture = TileNumber_texture(psTile->texture) | RUBBLE_TILE; - SET_TILE_DECAL(psTile); - markTileDirty(b.map.x + width, b.map.y + breadth); + makeTileRubbleTexture(psTile, x, y, RUBBLE_TILE); } - auxClearBlocking(b.map.x + width, b.map.y + breadth, AUXBITS_ALL); + auxClearBlocking(x, y, AUXBITS_ALL); } else { /* This remains a blocking tile */ psTile->psObject = nullptr; - auxClearBlocking(b.map.x + width, b.map.y + breadth, AIR_BLOCKED); // Shouldn't remain blocking for air units, however. + auxClearBlocking(x, y, AIR_BLOCKED); // Shouldn't remain blocking for air units, however. if (isUrban) { - psTile->texture = TileNumber_texture(psTile->texture) | BLOCKING_RUBBLE_TILE; - SET_TILE_DECAL(psTile); - markTileDirty(b.map.x + width, b.map.y + breadth); + makeTileRubbleTexture(psTile, x, y, BLOCKING_RUBBLE_TILE); } } } diff --git a/src/map.h b/src/map.h index 46035fd31c4..175a86601f7 100644 --- a/src/map.h +++ b/src/map.h @@ -524,6 +524,13 @@ WZ_DECL_ALWAYS_INLINE static inline bool worldOnMap(Vector2i pos) return worldOnMap(pos.x, pos.y); } +static inline void makeTileRubbleTexture(MAPTILE *psTile, const unsigned int x, const unsigned int y, const unsigned int newTexture) +{ + psTile->texture = TileNumber_texture(psTile->texture) | newTexture; + SET_TILE_DECAL(psTile); + markTileDirty(x, y); +} + /* Intersect a line with the map and report tile intersection points */ bool map_Intersect(int *Cx, int *Cy, int *Vx, int *Vy, int *Sx, int *Sy);