本文整理汇总了C++中ThingPtr类的典型用法代码示例。如果您正苦于以下问题:C++ ThingPtr类的具体用法?C++ ThingPtr怎么用?C++ ThingPtr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ThingPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeThing
bool Tile::removeThing(ThingPtr thing)
{
if(!thing)
return false;
bool removed = false;
if(thing->isEffect()) {
EffectPtr effect = thing->static_self_cast<Effect>();
auto it = std::find(m_effects.begin(), m_effects.end(), effect);
if(it != m_effects.end()) {
m_effects.erase(it);
removed = true;
}
} else {
auto it = std::find(m_things.begin(), m_things.end(), thing);
if(it != m_things.end()) {
m_things.erase(it);
removed = true;
}
}
thing->onDisappear();
if(thing->isTranslucent())
checkTranslucentLight();
return removed;
}
示例2: removeThing
bool Map::removeThing(const ThingPtr& thing)
{
if(!thing)
return false;
bool ret = false;
if(thing->isMissile()) {
MissilePtr missile = thing->static_self_cast<Missile>();
int z = missile->getPosition().z;
auto it = std::find(m_floorMissiles[z].begin(), m_floorMissiles[z].end(), missile);
if(it != m_floorMissiles[z].end()) {
m_floorMissiles[z].erase(it);
ret = true;
}
} else if(thing->isAnimatedText()) {
AnimatedTextPtr animatedText = thing->static_self_cast<AnimatedText>();
auto it = std::find(m_animatedTexts.begin(), m_animatedTexts.end(), animatedText);
if(it != m_animatedTexts.end()) {
m_animatedTexts.erase(it);
ret = true;
}
} else if(thing->isStaticText()) {
StaticTextPtr staticText = thing->static_self_cast<StaticText>();
auto it = std::find(m_staticTexts.begin(), m_staticTexts.end(), staticText);
if(it != m_staticTexts.end()) {
m_staticTexts.erase(it);
ret = true;
}
} else if(const TilePtr& tile = thing->getTile())
ret = tile->removeThing(thing);
notificateTileUpdate(thing->getPosition());
return ret;
}
示例3: rotate
void Game::rotate(const ThingPtr& thing)
{
if(!canPerformGameAction() || !thing)
return;
m_protocolGame->sendRotateItem(thing->getPosition(), thing->getId(), thing->getStackpos());
}
示例4: getTopMultiUseThing
ThingPtr Tile::getTopMultiUseThing()
{
if(isEmpty())
return nullptr;
if(CreaturePtr topCreature = getTopCreature())
return topCreature;
for(uint i = 0; i < m_things.size(); ++i) {
ThingPtr thing = m_things[i];
if(thing->isForceUse())
return thing;
}
for(uint i = 0; i < m_things.size(); ++i) {
ThingPtr thing = m_things[i];
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop()) {
if(i > 0 && thing->isSplash())
return m_things[i-1];
return thing;
}
}
for(uint i = 0; i < m_things.size(); ++i) {
ThingPtr thing = m_things[i];
if(!thing->isGround() && !thing->isOnTop())
return thing;
}
return m_things[0];
}
示例5: removeThing
void Map::removeThing(const ThingPtr& thing)
{
if(!thing)
return;
if(MissilePtr shot = thing->asMissile()) {
auto it = std::find(m_missilesAtFloor[shot->getPos().z].begin(), m_missilesAtFloor[shot->getPos().z].end(), shot);
if(it != m_missilesAtFloor[shot->getPos().z].end()) {
m_missilesAtFloor[shot->getPos().z].erase(it);
}
return;
}
else if(AnimatedTextPtr animatedText = thing->asAnimatedText()) {
auto it = std::find(m_animatedTexts.begin(), m_animatedTexts.end(), animatedText);
if(it != m_animatedTexts.end())
m_animatedTexts.erase(it);
return;
}
else if(StaticTextPtr staticText = thing->asStaticText()) {
auto it = std::find(m_staticTexts.begin(), m_staticTexts.end(), staticText);
if(it != m_staticTexts.end())
m_staticTexts.erase(it);
return;
}
if(TilePtr& tile = m_tiles[thing->getPos()])
tile->removeThing(thing);
}
示例6: getTopCreature
CreaturePtr Tile::getTopCreature()
{
CreaturePtr creature;
for(uint i = 0; i < m_things.size(); ++i) {
ThingPtr thing = m_things[i];
if(thing->isLocalPlayer()) // return local player if there is no other creature
creature = thing->static_self_cast<Creature>();
else if(thing->isCreature() && !thing->isLocalPlayer())
return thing->static_self_cast<Creature>();
}
if(!creature && !m_walkingCreatures.empty())
creature = m_walkingCreatures.back();
// check for walking creatures in tiles around
if(!creature) {
for(int xi=-1;xi<=1;++xi) {
for(int yi=-1;yi<=1;++yi) {
Position pos = m_position.translated(xi, yi);
if(pos == m_position)
continue;
const TilePtr& tile = g_map.getTile(pos);
if(tile) {
for(const CreaturePtr& c : tile->getCreatures()) {
if(c->isWalking() && c->getLastStepFromPosition() == m_position && c->getStepProgress() < 0.75f) {
creature = c;
}
}
}
}
}
}
return creature;
}
示例7: getThing
ItemPtr Tile::getGround()
{
ThingPtr firstObject = getThing(0);
if(!firstObject)
return nullptr;
if(firstObject->isGround() && firstObject->isItem())
return firstObject->static_self_cast<Item>();
return nullptr;
}
示例8: look
void Game::look(const ThingPtr& thing)
{
if(!canPerformGameAction() || !thing)
return;
if(thing->isCreature() && m_protocolVersion >= 961)
m_protocolGame->sendLookCreature(thing->getId());
else
m_protocolGame->sendLook(thing->getPosition(), thing->getId(), thing->getStackPos());
}
示例9: use
void Game::use(const ThingPtr& thing)
{
if(!canPerformGameAction() || !thing)
return;
Position pos = thing->getPosition();
if(!pos.isValid()) // virtual item
pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
m_protocolGame->sendUseItem(pos, thing->getId(), thing->getStackpos(), 0);
}
示例10: useInventoryItemWith
void Game::useInventoryItemWith(int itemId, const ThingPtr& toThing)
{
if(!canPerformGameAction() || !toThing)
return;
Position pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
if(toThing->isCreature())
m_protocolGame->sendUseOnCreature(pos, itemId, 0, toThing->getId());
else
m_protocolGame->sendUseItemWith(pos, itemId, 0, toThing->getPosition(), toThing->getId(), toThing->getStackpos());
}
示例11: getTopLookThing
ThingPtr Tile::getTopLookThing()
{
if(isEmpty())
return nullptr;
for(uint i = 0; i < m_things.size(); ++i) {
ThingPtr thing = m_things[i];
if(!thing->isIgnoreLook() && (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop()))
return thing;
}
return m_things[0];
}
示例12: use
void Game::use(const ThingPtr& thing)
{
if(!canPerformGameAction() || !thing)
return;
Position pos = thing->getPosition();
if(!pos.isValid()) // virtual item
pos = Position(0xFFFF, 0, 0); // inventory item
// some items, e.g. parcel, are not set as containers but they are.
// always try to use these items in free container slots.
m_protocolGame->sendUseItem(pos, thing->getId(), thing->getStackPos(), findEmptyContainerId());
}
示例13: useWith
void Game::useWith(const ItemPtr& item, const ThingPtr& toThing)
{
if(!canPerformGameAction() || !item || !toThing)
return;
Position pos = item->getPosition();
if(!pos.isValid()) // virtual item
pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
if(toThing->isCreature())
m_protocolGame->sendUseOnCreature(pos, item->getId(), item->getStackpos(), toThing->getId());
else
m_protocolGame->sendUseItemWith(pos, item->getId(), item->getStackpos(), toThing->getPosition(), toThing->getId(), toThing->getStackpos());
}
示例14: move
void Game::move(const ThingPtr& thing, const Position& toPos, int count)
{
if(count <= 0)
count = 1;
if(!canPerformGameAction() || !thing || thing->getPosition() == toPos)
return;
uint id = thing->getId();
if(thing->isCreature()) {
CreaturePtr creature = thing->static_self_cast<Creature>();
id = Proto::Creature;
}
m_protocolGame->sendMove(thing->getPosition(), id, thing->getStackpos(), toPos, count);
}
示例15: addThing
void Map::addThing(const ThingPtr& thing, const Position& pos, int stackPos)
{
if(!thing)
return;
if(MissilePtr shot = thing->asMissile()) {
m_missilesAtFloor[shot->getPosition().z].push_back(shot);
return;
}
TilePtr tile = getTile(pos);
tile->addThing(thing, stackPos);
if(CreaturePtr creature = thing->asCreature())
m_creatures[creature->getId()] = creature;
}