uint32_t Map::clean()
{
uint64_t start = OTSYS_TIME();
uint32_t count = 0, tiles = 0;
if (g_game.getGameState() == GAME_STATE_NORMAL) {
g_game.setGameState(GAME_STATE_MAINTAIN);
}
for (int32_t z = 0; z < (int32_t)MAP_MAX_LAYERS; z++) {
for (uint32_t y = 1; y <= mapHeight; y++) {
for (uint32_t x = 1; x <= mapWidth; x++) {
Tile* tile = getTile(x, y, z);
if (!tile || tile->hasFlag(TILESTATE_HOUSE) || !tile->getItemList()) {
continue;
}
++tiles;
TileItemVector* itemList = tile->getItemList();
ItemVector::iterator it = itemList->begin(), end = itemList->end();
while (it != end) {
if ((*it)->isCleanable()) {
g_game.internalRemoveItem(*it, -1);
it = itemList->begin();
end = itemList->end();
++count;
} else {
++it;
}
}
}
}
}
if (g_game.getGameState() == GAME_STATE_MAINTAIN) {
g_game.setGameState(GAME_STATE_NORMAL);
}
std::cout << "> CLEAN: Removed " << count << " item" << (count != 1 ? "s" : "")
<< " from " << tiles << " tile" << (tiles != 1 ? "s" : "") << " in "
<< (OTSYS_TIME() - start) / (1000.) << " seconds." << std::endl;
return count;
}