cell AMX_NATIVE_CALL Natives::Streamer_DestroyAllVisibleItems(AMX *amx, cell *params) { CHECK_PARAMS(3, "Streamer_DestroyAllVisibleItems"); bool serverWide = static_cast<int>(params[3]) != 0; switch (static_cast<int>(params[2])) { case STREAMER_TYPE_PICKUP: { boost::unordered_map<int, int>::iterator p = core->getData()->internalPickups.begin(); while (p != core->getData()->internalPickups.end()) { boost::unordered_map<int, Item::SharedPickup>::iterator q = core->getData()->pickups.find(p->first); if (serverWide || (q != core->getData()->pickups.end() && q->second->amx == amx)) { DestroyPickup(p->second); p = core->getData()->internalPickups.erase(p); } else { ++p; } } return 1; } case STREAMER_TYPE_VEHICLE: { boost::unordered_map<int, int>::iterator p = core->getData()->internalVehicles.begin(); while (p != core->getData()->internalPickups.end()) { boost::unordered_map<int, Item::SharedVehicle>::iterator q = core->getData()->vehicles.find(p->first); if (serverWide || (q != core->getData()->vehicles.end() && q->second->amx == amx)) { DestroyVehicle(p->second); p = core->getData()->internalVehicles.erase(p); } else { ++p; } } return 1; } } boost::unordered_map<int, Player>::iterator p = core->getData()->players.find(static_cast<int>(params[1])); if (p != core->getData()->players.end()) { switch (static_cast<int>(params[2])) { case STREAMER_TYPE_OBJECT: { boost::unordered_map<int, int>::iterator o = p->second.internalObjects.begin(); while (o != p->second.internalObjects.end()) { boost::unordered_map<int, Item::SharedObject>::iterator q = core->getData()->objects.find(o->first); if (serverWide || (q != core->getData()->objects.end() && q->second->amx == amx)) { DestroyPlayerObject(p->first, o->second); o = p->second.internalObjects.erase(o); } else { ++o; } } return 1; } case STREAMER_TYPE_CP: { if (p->second.visibleCheckpoint) { boost::unordered_map<int, Item::SharedCheckpoint>::iterator c = core->getData()->checkpoints.find(p->second.visibleCheckpoint); if (serverWide || (c != core->getData()->checkpoints.end() && c->second->amx == amx)) { DisablePlayerCheckpoint(p->first); p->second.activeCheckpoint = 0; p->second.visibleCheckpoint = 0; return 1; } } return 0; } case STREAMER_TYPE_RACE_CP: { if (p->second.visibleRaceCheckpoint) { boost::unordered_map<int, Item::SharedRaceCheckpoint>::iterator r = core->getData()->raceCheckpoints.find(p->second.visibleRaceCheckpoint); if (serverWide || (r != core->getData()->raceCheckpoints.end() && r->second->amx == amx)) { DisablePlayerRaceCheckpoint(p->first); p->second.activeRaceCheckpoint = 0; p->second.visibleRaceCheckpoint = 0; return 1; } } return 0; } case STREAMER_TYPE_MAP_ICON: { boost::unordered_map<int, int>::iterator m = p->second.internalMapIcons.begin(); while (m != p->second.internalMapIcons.end()) { boost::unordered_map<int, Item::SharedMapIcon>::iterator n = core->getData()->mapIcons.find(m->first); if (serverWide || (n != core->getData()->mapIcons.end() && n->second->amx == amx)) { RemovePlayerMapIcon(p->first, m->second); m = p->second.internalMapIcons.erase(m); } else { ++m; } } return 1; } case STREAMER_TYPE_3D_TEXT_LABEL: { boost::unordered_map<int, int>::iterator t = p->second.internalTextLabels.begin(); while (t != p->second.internalMapIcons.end()) { boost::unordered_map<int, Item::SharedTextLabel>::iterator u = core->getData()->textLabels.find(t->first); if (serverWide || (u != core->getData()->textLabels.end() && u->second->amx == amx)) { DeletePlayer3DTextLabel(p->first, t->second); t = p->second.internalTextLabels.erase(t); } else { ++t; } } return 1; } case STREAMER_TYPE_AREA: { boost::unordered_set<int>::iterator a = p->second.internalAreas.begin(); while (a != p->second.internalAreas.end()) { boost::unordered_map<int, Item::SharedArea>::iterator b = core->getData()->areas.find(*a); if (serverWide || (b != core->getData()->areas.end() && b->second->amx == amx)) { a = p->second.internalAreas.erase(a); } else { ++a; } } return 1; } default: { Utility::logError("Streamer_DestroyAllVisibleItems: Invalid type specified"); return 0; } } } return 0; }
void Streamer::processMapIcons(Player &player, const std::vector<SharedCell> &cells) { std::multimap<float, Item::SharedMapIcon> discoveredMapIcons, existingMapIcons; for (std::vector<SharedCell>::const_iterator c = cells.begin(); c != cells.end(); ++c) { for (boost::unordered_map<int, Item::SharedMapIcon>::const_iterator m = (*c)->mapIcons.begin(); m != (*c)->mapIcons.end(); ++m) { float distance = std::numeric_limits<float>::infinity(); if (checkPlayer(m->second->players, player.playerID, m->second->interiors, player.interiorID, m->second->worlds, player.worldID)) { distance = static_cast<float>(boost::geometry::comparable_distance(player.position, m->second->position)); } boost::unordered_map<int, int>::iterator i = player.internalMapIcons.find(m->first); if (distance <= m->second->streamDistance) { if (i == player.internalMapIcons.end()) { discoveredMapIcons.insert(std::make_pair(distance, m->second)); } else { if (m->second->cell) { player.visibleCell->mapIcons.insert(*m); } existingMapIcons.insert(std::make_pair(distance, m->second)); } } else { if (i != player.internalMapIcons.end()) { RemovePlayerMapIcon(player.playerID, i->second); player.mapIconIdentifier.remove(i->second, player.internalMapIcons.size()); player.internalMapIcons.quick_erase(i); } } } } for (std::multimap<float, Item::SharedMapIcon>::iterator d = discoveredMapIcons.begin(); d != discoveredMapIcons.end(); ++d) { if (player.internalMapIcons.size() == visibleMapIcons) { std::multimap<float, Item::SharedMapIcon>::reverse_iterator e = existingMapIcons.rbegin(); if (e != existingMapIcons.rend()) { if (d->first < e->first) { boost::unordered_map<int, int>::iterator i = player.internalMapIcons.find(e->second->mapIconID); if (i != player.internalMapIcons.end()) { RemovePlayerMapIcon(player.playerID, i->second); player.mapIconIdentifier.remove(i->second, player.internalMapIcons.size()); player.internalMapIcons.quick_erase(i); } if (e->second->cell) { player.visibleCell->mapIcons.erase(e->second->mapIconID); } existingMapIcons.erase(--e.base()); } } if (player.internalMapIcons.size() == visibleMapIcons) { break; } } int internalID = player.mapIconIdentifier.get(); SetPlayerMapIcon(player.playerID, internalID, d->second->position[0], d->second->position[1], d->second->position[2], d->second->type, d->second->color, d->second->style); player.internalMapIcons.insert(std::make_pair(d->second->mapIconID, internalID)); if (d->second->cell) { player.visibleCell->mapIcons.insert(std::make_pair(d->second->mapIconID, d->second)); } } }