* Stops animation on the given tile. * @param tile the tile to remove * @param immediate immediately delete the tile from the animated tile list instead of waiting for the next tick. */
| 25 | * @param immediate immediately delete the tile from the animated tile list instead of waiting for the next tick. |
| 26 | */ |
| 27 | void DeleteAnimatedTile(TileIndex tile, bool immediate) |
| 28 | { |
| 29 | if (immediate) { |
| 30 | if (GetAnimatedTileState(tile) == AnimatedTileState::None) return; |
| 31 | |
| 32 | /* The tile may be switched to a non-animatable tile soon, so we should remove it from the |
| 33 | * animated tile list early. */ |
| 34 | SetAnimatedTileState(tile, AnimatedTileState::None); |
| 35 | |
| 36 | /* To avoid having to move everything after this tile in the animated tile list, look for this tile |
| 37 | * in the animated tile list and replace with last entry if not last. */ |
| 38 | auto it = std::ranges::find(_animated_tiles, tile); |
| 39 | if (it == std::end(_animated_tiles)) return; |
| 40 | |
| 41 | if (std::next(it) != std::end(_animated_tiles)) *it = _animated_tiles.back(); |
| 42 | _animated_tiles.pop_back(); |
| 43 | |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | /* If the tile was animated, mark it for deletion from the tile list on the next animation loop. */ |
| 48 | if (GetAnimatedTileState(tile) == AnimatedTileState::Animated) SetAnimatedTileState(tile, AnimatedTileState::Deleted); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Add the given tile to the animated tile table (if it does not exist yet). |
no test coverage detected