Make g_map.findItemsById return a map instead of a vector

master
Ahmed Samy 11 years ago
parent e741a62ce9
commit 537508021e

@ -375,17 +375,19 @@ void Map::endGhostMode()
g_painter->resetOpacity(); g_painter->resetOpacity();
} }
ItemVector Map::findItemsById(uint16 clientId, uint32 max) std::map<Position, ItemPtr> Map::findItemsById(uint16 clientId, uint32 max)
{ {
ItemVector ret; std::map<Position, ItemPtr> ret;
uint32 count = 0; uint32 count = 0;
for(uint8_t z = 0; z <= Otc::MAX_Z; ++z) { for(uint8_t z = 0; z <= Otc::MAX_Z; ++z) {
for(const auto& pair : m_tileBlocks[z]) { for(const auto& pair : m_tileBlocks[z]) {
const TileBlock& block = pair.second; const TileBlock& block = pair.second;
for(const TilePtr& tile : block.getTiles()) { for(const TilePtr& tile : block.getTiles()) {
if(unlikely(!tile || tile->isEmpty()))
continue;
for(const ItemPtr& item : tile->getItems()) { for(const ItemPtr& item : tile->getItems()) {
if(item->getId() == clientId) { if(item->getId() == clientId) {
ret.push_back(item); ret.insert(std::make_pair(tile->getPosition(), item));
if(++count >= max) if(++count >= max)
break; break;
} }

@ -197,7 +197,7 @@ public:
void beginGhostMode(float opacity); void beginGhostMode(float opacity);
void endGhostMode(); void endGhostMode();
ItemVector findItemsById(uint16 clientId, uint32 max); std::map<Position, ItemPtr> findItemsById(uint16 clientId, uint32 max);
// known creature related // known creature related
void addCreature(const CreaturePtr& creature); void addCreature(const CreaturePtr& creature);

@ -189,6 +189,8 @@ public:
bool isInRange(const Position& pos, int minXRange, int maxXRange, int minYRange, int maxYRange) const { bool isInRange(const Position& pos, int minXRange, int maxXRange, int minYRange, int maxYRange) const {
return (pos.x >= x-minXRange && pos.x <= x+maxXRange && pos.y >= y-minYRange && pos.y <= y+maxYRange && pos.z == z); return (pos.x >= x-minXRange && pos.x <= x+maxXRange && pos.y >= y-minYRange && pos.y <= y+maxYRange && pos.z == z);
} }
// operator less than for std::map
bool operator<(const Position& other) const { return x < other.x && y < other.y && z < other.z; }
bool up(int n = 1) { bool up(int n = 1) {
int nz = z-n; int nz = z-n;

Loading…
Cancel
Save