本文整理汇总了C++中CreatureVector::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ CreatureVector::erase方法的具体用法?C++ CreatureVector::erase怎么用?C++ CreatureVector::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CreatureVector
的用法示例。
在下文中一共展示了CreatureVector::erase方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeThing
void Tile::removeThing(Thing* thing, uint32_t count)
{
Creature* creature = thing->getCreature();
if (creature) {
CreatureVector* creatures = getCreatures();
if (creatures) {
CreatureVector::iterator it = std::find(creatures->begin(), creatures->end(), thing);
if (it != creatures->end()) {
g_game.map.clearSpectatorCache();
creatures->erase(it);
}
}
return;
}
Item* item = thing->getItem();
if (!item) {
return;
}
int32_t index = getThingIndex(item);
if (index == -1) {
return;
}
if (item == ground) {
ground->setParent(nullptr);
ground = nullptr;
SpectatorVec list;
g_game.map.getSpectators(list, getPosition(), true);
onRemoveTileItem(list, std::vector<int32_t>(list.size(), 0), item);
return;
}
TileItemVector* items = getItemList();
if (!items) {
return;
}
const ItemType& itemType = Item::items[item->getID()];
if (itemType.alwaysOnTop) {
auto it = std::find(items->getBeginTopItem(), items->getEndTopItem(), item);
if (it == items->getEndTopItem()) {
return;
}
std::vector<int32_t> oldStackPosVector;
SpectatorVec list;
g_game.map.getSpectators(list, getPosition(), true);
for (Creature* spectator : list) {
if (Player* tmpPlayer = spectator->getPlayer()) {
oldStackPosVector.push_back(getStackposOfItem(tmpPlayer, item));
}
}
item->setParent(nullptr);
items->erase(it);
onRemoveTileItem(list, oldStackPosVector, item);
} else {
auto it = std::find(items->getBeginDownItem(), items->getEndDownItem(), item);
if (it == items->getEndDownItem()) {
return;
}
if (itemType.stackable && count != item->getItemCount()) {
uint8_t newCount = static_cast<uint8_t>(std::max<int32_t>(0, static_cast<int32_t>(item->getItemCount() - count)));
item->setItemCount(newCount);
onUpdateTileItem(item, itemType, item, itemType);
} else {
std::vector<int32_t> oldStackPosVector;
SpectatorVec list;
g_game.map.getSpectators(list, getPosition(), true);
for (Creature* spectator : list) {
if (Player* tmpPlayer = spectator->getPlayer()) {
oldStackPosVector.push_back(getStackposOfItem(tmpPlayer, item));
}
}
item->setParent(nullptr);
items->erase(it);
items->addDownItemCount(-1);
onRemoveTileItem(list, oldStackPosVector, item);
}
}
}
示例2: __removeThing
void Tile::__removeThing(Thing* thing, uint32_t count)
{
Creature* creature = thing->getCreature();
if (creature) {
CreatureVector* creatures = getCreatures();
if (creatures) {
CreatureVector::iterator it = std::find(creatures->begin(), creatures->end(), thing);
if (it != creatures->end()) {
g_game.clearSpectatorCache();
creatures->erase(it);
}
}
return;
}
Item* item = thing->getItem();
if (item) {
int32_t index = __getIndexOfThing(item);
if (index == -1) {
return;
}
if (item == ground) {
const SpectatorVec& list = g_game.getSpectators(getPosition());
std::vector<uint32_t> oldStackPosVector;
for (SpectatorVec::const_iterator it = list.begin(), end = list.end(); it != end; ++it) {
if (Player* tmpPlayer = (*it)->getPlayer()) {
oldStackPosVector.push_back(getClientIndexOfThing(tmpPlayer, ground));
}
}
ground->setParent(NULL);
ground = NULL;
onRemoveTileItem(list, oldStackPosVector, item);
return;
}
if (item->isAlwaysOnTop()) {
TileItemVector* items = getItemList();
if (items) {
for (ItemVector::iterator it = items->getBeginTopItem(); it != items->getEndTopItem(); ++it) {
if (*it == item) {
const SpectatorVec& list = g_game.getSpectators(getPosition());
std::vector<uint32_t> oldStackPosVector;
for (SpectatorVec::const_iterator iit = list.begin(), iend = list.end(); iit != iend; ++iit) {
if (Player* tmpPlayer = (*iit)->getPlayer()) {
oldStackPosVector.push_back(getClientIndexOfThing(tmpPlayer, *it));
}
}
(*it)->setParent(NULL);
items->erase(it);
onRemoveTileItem(list, oldStackPosVector, item);
return;
}
}
}
} else {
TileItemVector* items = getItemList();
if (items) {
for (ItemVector::iterator it = items->getBeginDownItem(); it != items->getEndDownItem(); ++it) {
if (*it == item) {
if (item->isStackable() && count != item->getItemCount()) {
uint8_t newCount = (uint8_t)std::max<int32_t>(0, (int32_t)(item->getItemCount() - count));
updateTileFlags(item, true);
item->setItemCount(newCount);
updateTileFlags(item, false);
const ItemType& it = Item::items[item->getID()];
onUpdateTileItem(item, it, item, it);
} else {
const SpectatorVec& list = g_game.getSpectators(getPosition());
std::vector<uint32_t> oldStackPosVector;
for (SpectatorVec::const_iterator iit = list.begin(), iend = list.end(); iit != iend; ++iit) {
if (Player* tmpPlayer = (*iit)->getPlayer()) {
oldStackPosVector.push_back(getClientIndexOfThing(tmpPlayer, *it));
}
}
(*it)->setParent(NULL);
items->erase(it);
--items->downItemCount;
onRemoveTileItem(list, oldStackPosVector, item);
}
//.........这里部分代码省略.........